src/strings.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 23:20:33 +0300
changeset 11184 88c967f1422b
parent 11161 7d0fac8f14cd
permissions -rw-r--r--
add an empty bin/cache dir
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (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: 10402
diff changeset
     3
/** @file strings.cpp Handling of translated strings. */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1853
diff changeset
     6
#include "openttd.h"
2291
2b064aa97f91 (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"
9260
fc088947405b (svn r12460) -Change: rename src/namegen.h to src/namegen_func.h so MSVC can have both files in it's treelist.
rubidium
parents: 9259
diff changeset
     8
#include "namegen_func.h"
9281
d8cd9ac52a68 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 9260
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
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 425
diff changeset
    11
#include "screenshot.h"
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1376
diff changeset
    12
#include "waypoint.h"
2070
26c657906f25 (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
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    14
#include "variables.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
    15
#include "newgrf_text.h"
4120
90e678fd7d8d (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
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4920
diff changeset
    17
#include "industry.h"
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
    18
#include "fileio.h"
6417
26acff62d001 (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: 6414
diff changeset
    19
#include "cargotype.h"
7139
4ae3ab180d05 (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: 6988
diff changeset
    20
#include "group.h"
4ae3ab180d05 (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: 6988
diff changeset
    21
#include "debug.h"
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
    22
#include "newgrf_townname.h"
9286
d446bf9f4a68 (svn r12501) -Codechange: split signs.h.
rubidium
parents: 9282
diff changeset
    23
#include "signs_base.h"
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
    24
#include "newgrf_engine.h"
8582
9d7754037bde (svn r11647) -Fix (r11646): it did not compile without freetype...
rubidium
parents: 8581
diff changeset
    25
#include "spritecache.h"
8581
8e4e36a205fe (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: 8450
diff changeset
    26
#include "fontcache.h"
8e4e36a205fe (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: 8450
diff changeset
    27
#include "gui.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8583
diff changeset
    28
#include "strings_func.h"
8627
448ebf3a8291 (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: 8626
diff changeset
    29
#include "functions.h"
10402
b168fbb99f7c (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 10382
diff changeset
    30
#include "rev.h"
8616
0c0b4b5a67ce (svn r11681) -Fix (r11674): hopefully fix the compile error on big endian machines.
rubidium
parents: 8610
diff changeset
    31
#include "core/endian_func.hpp"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8628
diff changeset
    32
#include "date_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8636
diff changeset
    33
#include "vehicle_base.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8698
diff changeset
    34
#include "string_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    35
#include "player_func.h"
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    36
#include "player_base.h"
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    37
#include "fios.h"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8760
diff changeset
    38
#include "settings_type.h"
8771
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8766
diff changeset
    39
#include "video/video_driver.hpp"
9282
2bb9703aeb39 (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: 9281
diff changeset
    40
#include "engine_func.h"
10382
d1d4452acbfc (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: 10261
diff changeset
    41
#include "engine_base.h"
10250
e64ee7484b43 (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: 10229
diff changeset
    42
#include "saveload.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    44
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    45
#include "table/control_codes.h"
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
    46
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
    47
DynamicLanguages _dynlang;
7762
03721db0ac1c (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7555
diff changeset
    48
uint64 _decode_parameters[20];
2201
3300b6ce8bce (svn r2717) Move _userstring to strings.[ch]
tron
parents: 2186
diff changeset
    49
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
    50
static char *StationGetSpecialString(char *buff, int x, const char* last);
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
    51
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last);
7498
ce6588257e8d (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: 7492
diff changeset
    52
static char *GetSpecialPlayerNameString(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
    53
7498
ce6588257e8d (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: 7492
diff changeset
    54
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
    55
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    56
struct LanguagePack {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
    57
	uint32 ident;       // 32-bits identifier
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    58
	uint32 version;     // 32-bits of auto generated version info which is basically a hash of strings.h
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    59
	char name[32];      // the international name of this language
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    60
	char own_name[32];  // the localized name of this language
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    61
	char isocode[16];   // the ISO code for the language (not country code)
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    62
	uint16 offsets[32]; // the offsets
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    63
	byte plural_form;   // how to compute plural forms
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4416
diff changeset
    64
	byte pad[3];        // pad header to be a multiple of 4
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
    65
	char data[VARARRAY_SIZE]; // list of strings
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    66
};
1319
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    67
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    68
static char **_langpack_offs;
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    69
static LanguagePack *_langpack;
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
    70
static uint _langtab_num[32];   // Offset into langpack offs
1319
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    71
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
    72
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
    74
/** Read an int64 from the argv array. */
7498
ce6588257e8d (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: 7492
diff changeset
    75
static inline int64 GetInt64(const int64 **argv)
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    76
{
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    77
	assert(argv);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    78
	return *(*argv)++;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    79
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    80
7498
ce6588257e8d (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: 7492
diff changeset
    81
/** Read an int32 from the argv array. */
ce6588257e8d (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: 7492
diff changeset
    82
static inline int32 GetInt32(const int64 **argv)
ce6588257e8d (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: 7492
diff changeset
    83
{
ce6588257e8d (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: 7492
diff changeset
    84
	return (int32)GetInt64(argv);
ce6588257e8d (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: 7492
diff changeset
    85
}
ce6588257e8d (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: 7492
diff changeset
    86
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
    87
/** Read an array from the argv array. */
7498
ce6588257e8d (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: 7492
diff changeset
    88
static inline const int64 *GetArgvPtr(const int64 **argv, int n)
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    89
{
7498
ce6588257e8d (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: 7492
diff changeset
    90
	const int64 *result;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    91
	assert(*argv);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    92
	result = *argv;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    93
	(*argv) += n;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    94
	return result;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    95
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    96
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    97
8941
f93c669d3ca6 (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: 8819
diff changeset
    98
const char *GetStringPtr(StringID string)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
{
8941
f93c669d3ca6 (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: 8819
diff changeset
   100
	switch (GB(string, 11, 5)) {
f93c669d3ca6 (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: 8819
diff changeset
   101
		case 28: return GetGRFStringPtr(GB(string, 0, 11));
f93c669d3ca6 (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: 8819
diff changeset
   102
		case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
f93c669d3ca6 (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: 8819
diff changeset
   103
		case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
f93c669d3ca6 (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: 8819
diff changeset
   104
		default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
f93c669d3ca6 (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: 8819
diff changeset
   105
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   108
/** The highest 8 bits of string contain the "case index".
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   109
 * These 8 bits will only be set when FormatString wants to print
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   110
 * the string in a different case. No one else except FormatString
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   111
 * should set those bits, therefore string CANNOT be StringID, but uint32.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   112
 * @param buffr
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   113
 * @param string
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   114
 * @param argv
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   115
 * @param last
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   116
 * @return a formatted string of char
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   117
 */
7498
ce6588257e8d (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: 7492
diff changeset
   118
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
   119
{
8306
e3f8ee5113ed (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: 8259
diff changeset
   120
	if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, last);
e3f8ee5113ed (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: 8259
diff changeset
   121
2140
d708eb80ab8b (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
   122
	uint index = GB(string,  0, 11);
d708eb80ab8b (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
   123
	uint tab   = GB(string, 11,  5);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   125
	switch (tab) {
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   126
		case 4:
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   127
			if (index >= 0xC0)
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   128
				return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv), last);
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   129
			break;
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   130
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   131
		case 14:
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   132
			if (index >= 0xE4)
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   133
				return GetSpecialPlayerNameString(buffr, index - 0xE4, argv, last);
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   134
			break;
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   135
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   136
		case 15:
8941
f93c669d3ca6 (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: 8819
diff changeset
   137
			/* Old table for custom names. This is no longer used */
f93c669d3ca6 (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: 8819
diff changeset
   138
			error("Incorrect conversion of custom name string.");
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   139
4710
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   140
		case 26:
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   141
			/* Include string within newgrf text (format code 81) */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8368
diff changeset
   142
			if (HasBit(index, 10)) {
4710
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   143
				StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   144
				return GetStringWithArgs(buffr, string, argv, last);
4710
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   145
			}
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   146
			break;
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   147
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   148
		case 28:
8941
f93c669d3ca6 (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: 8819
diff changeset
   149
			return FormatString(buffr, GetGRFStringPtr(index), argv, 0, last);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   150
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   151
		case 29:
8941
f93c669d3ca6 (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: 8819
diff changeset
   152
			return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, 0, last);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   153
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   154
		case 30:
8941
f93c669d3ca6 (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: 8819
diff changeset
   155
			return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, 0, last);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   156
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   157
		case 31:
11157
a0173588b15e (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: 10998
diff changeset
   158
			NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   161
	if (index >= _langtab_num[tab]) {
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   162
		error(
10839
a62547c31fdb (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: 10835
diff changeset
   163
			"String 0x%X is invalid. "
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   164
			"Probably because an old version of the .lng file.\n", string
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   165
		);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   166
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   168
	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
   169
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   171
char *GetString(char *buffr, StringID string, const char* last)
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   172
{
7498
ce6588257e8d (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: 7492
diff changeset
   173
	return GetStringWithArgs(buffr, string, (int64*)_decode_parameters, last);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   174
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   175
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   176
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   177
char *InlineString(char *buf, StringID string)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   178
{
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   179
	buf += Utf8Encode(buf, SCC_STRING_ID);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   180
	buf += Utf8Encode(buf, string);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   181
	return buf;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   182
}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   183
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   184
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   185
/** This function is used to "bind" a C string to a OpenTTD dparam slot.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   186
 * @param n slot of the string
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   187
 * @param str string to bind
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   188
 */
2055
9361b56db8ba (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
   189
void SetDParamStr(uint n, const char *str)
9361b56db8ba (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
   190
{
11157
a0173588b15e (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: 10998
diff changeset
   191
	SetDParam(n, (uint64)str);
2055
9361b56db8ba (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
   192
}
9361b56db8ba (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
   193
1309
dab90d4cbf2d (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1306
diff changeset
   194
void InjectDParam(int amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
{
7502
71f5d2c6a605 (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: 7501
diff changeset
   196
	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
   197
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   199
// TODO
7852
d2491d19f323 (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: 7844
diff changeset
   200
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
   201
{
7852
d2491d19f323 (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: 7844
diff changeset
   202
	uint64 divisor = 10000000000000000000ULL;
d2491d19f323 (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: 7844
diff changeset
   203
	uint64 quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	int i;
7852
d2491d19f323 (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: 7844
diff changeset
   205
	uint64 tot;
d2491d19f323 (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: 7844
diff changeset
   206
	uint64 num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	if (number < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		*buff++ = '-';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	tot = 0;
7852
d2491d19f323 (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: 7844
diff changeset
   216
	for (i = 0; i < 20; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
		quot = 0;
7852
d2491d19f323 (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: 7844
diff changeset
   218
		if (num >= divisor) {
d2491d19f323 (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: 7844
diff changeset
   219
			quot = num / divisor;
d2491d19f323 (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: 7844
diff changeset
   220
			num = num % divisor;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		}
7852
d2491d19f323 (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: 7844
diff changeset
   222
		if (tot |= quot || i == 19) {
1312
8defbb525d09 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   223
			*buff++ = '0' + quot;
7852
d2491d19f323 (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: 7844
diff changeset
   224
			if ((i % 3) == 1 && i != 19) *buff++ = ',';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
		}
7852
d2491d19f323 (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: 7844
diff changeset
   226
d2491d19f323 (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: 7844
diff changeset
   227
		divisor /= 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   230
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   235
// TODO
7852
d2491d19f323 (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: 7844
diff changeset
   236
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
   237
{
7852
d2491d19f323 (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: 7844
diff changeset
   238
	uint64 divisor = 10000000000000000000ULL;
d2491d19f323 (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: 7844
diff changeset
   239
	uint64 quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	int i;
7852
d2491d19f323 (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: 7844
diff changeset
   241
	uint64 tot;
d2491d19f323 (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: 7844
diff changeset
   242
	uint64 num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	if (number < 0) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   245
		buff = strecpy(buff, "-", last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	tot = 0;
7852
d2491d19f323 (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: 7844
diff changeset
   252
	for (i = 0; i < 20; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		quot = 0;
7852
d2491d19f323 (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: 7844
diff changeset
   254
		if (num >= divisor) {
d2491d19f323 (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: 7844
diff changeset
   255
			quot = num / divisor;
d2491d19f323 (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: 7844
diff changeset
   256
			num = num % divisor;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
		}
7852
d2491d19f323 (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: 7844
diff changeset
   258
		if (tot |= quot || i == 19) {
1312
8defbb525d09 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   259
			*buff++ = '0' + quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		}
7852
d2491d19f323 (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: 7844
diff changeset
   261
d2491d19f323 (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: 7844
diff changeset
   262
		divisor /= 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   265
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   271
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
   272
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	YearMonthDay ymd;
4289
ff1b2b915cab (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4288
diff changeset
   274
	ConvertDateToYMD(date, &ymd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
7498
ce6588257e8d (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: 7492
diff changeset
   276
	int64 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
6484
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   277
	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
   278
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   280
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
   281
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	YearMonthDay ymd;
4289
ff1b2b915cab (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4288
diff changeset
   283
	ConvertDateToYMD(date, &ymd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
7498
ce6588257e8d (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: 7492
diff changeset
   285
	int64 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
6484
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   286
	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
   287
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   289
static char *FormatTinyDate(char *buff, Date date, const char* last)
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   290
{
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   291
	YearMonthDay ymd;
4289
ff1b2b915cab (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4288
diff changeset
   292
	ConvertDateToYMD(date, &ymd);
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   293
6484
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   294
	char day[3];
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   295
	char month[3];
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   296
	/* We want to zero-pad the days and months */
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   297
	snprintf(day,   lengthof(day),   "%02i", ymd.day);
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   298
	snprintf(month, lengthof(month), "%02i", ymd.month + 1);
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   299
11157
a0173588b15e (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: 10998
diff changeset
   300
	int64 args[3] = { (int64)day, (int64)month, ymd.year };
6484
8258acaa52c8 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6417
diff changeset
   301
	return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   302
}
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   303
7492
6e76d5fd4ca7 (svn r10252) -Fix: never overflow when applying exchange rates before drawing the amount of money.
rubidium
parents: 7490
diff changeset
   304
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
   305
{
8259
127e5d73637d (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: 8112
diff changeset
   306
	/* We are going to make number absolute for printing, so
127e5d73637d (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: 8112
diff changeset
   307
	 * keep this piece of data as we need it later on */
127e5d73637d (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: 8112
diff changeset
   308
	bool negative = number < 0;
127e5d73637d (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: 8112
diff changeset
   309
	const char *multiplier = "";
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   310
	char buf[40];
8259
127e5d73637d (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: 8112
diff changeset
   311
	char *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
8259
127e5d73637d (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: 8112
diff changeset
   314
	number *= spec->rate;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   316
	/* convert from negative */
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   317
	if (number < 0) {
7918
3b2e2a49a093 (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: 7907
diff changeset
   318
		if (buff + Utf8CharLen(SCC_RED) > last) return buff;
3b2e2a49a093 (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: 7907
diff changeset
   319
		buff += Utf8Encode(buff, SCC_RED);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   320
		buff = strecpy(buff, "-", last);
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   321
		number = -number;
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   322
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   323
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   324
	/* Add prefix part, folowing symbol_pos specification.
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   325
	 * Here, it can can be either 0 (prefix) or 2 (both prefix anf suffix).
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   326
	 * The only remaining value is 1 (suffix), so everything that is not 1 */
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   327
	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
   328
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   329
	/* 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
   330
	if (compact) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		if (number >= 1000000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
			number = (number + 500000) / 1000000;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   333
			multiplier = "M";
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
		} else if (number >= 1000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
			number = (number + 500) / 1000;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   336
			multiplier = "k";
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   337
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   339
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   340
	/* convert to ascii number and add commas */
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   341
	p = endof(buf);
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   342
	*--p = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	j = 4;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   344
	do {
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   345
		if (--j == 0) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   346
			*--p = spec->separator;
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   347
			j = 3;
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   348
		}
8259
127e5d73637d (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: 8112
diff changeset
   349
		*--p = '0' + (char)(number % 10);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   350
	} while ((number /= 10) != 0);
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   351
	buff = strecpy(buff, p, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   353
	buff = strecpy(buff, multiplier, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   355
	/* Add suffix part, folowing symbol_pos specification.
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   356
	 * Here, it can can be either 1 (suffix) or 2 (both prefix anf suffix).
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   357
	 * The only remaining value is 1 (prefix), so everything that is not 0 */
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   358
	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
   359
8259
127e5d73637d (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: 8112
diff changeset
   360
	if (negative) {
7918
3b2e2a49a093 (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: 7907
diff changeset
   361
		if (buff + Utf8CharLen(SCC_PREVIOUS_COLOUR) > last) return buff;
3b2e2a49a093 (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: 7907
diff changeset
   362
		buff += Utf8Encode(buff, SCC_PREVIOUS_COLOUR);
3b2e2a49a093 (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: 7907
diff changeset
   363
		*buff = '\0';
3b2e2a49a093 (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: 7907
diff changeset
   364
	}
3b2e2a49a093 (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: 7907
diff changeset
   365
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   369
static int DeterminePluralForm(int64 count)
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   370
{
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   371
	/* The absolute value determines plurality */
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   372
	uint64 n = abs(count);
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   373
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   374
	switch (_langpack->plural_form) {
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   375
		default:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   376
			NOT_REACHED();
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   377
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   378
		/* Two forms, singular used for one only
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   379
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   380
		 *   Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish,
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   381
		 *   Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   382
		case 0:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   383
			return n != 1;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   384
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   385
		/* Only one form
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   386
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   387
		 *   Hungarian, Japanese, Korean, Turkish */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   388
		case 1:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   389
			return 0;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   390
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   391
		/* Two forms, singular used for zero and one
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   392
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   393
		 *   French, Brazilian Portuguese */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   394
		case 2:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   395
			return n > 1;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   396
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   397
		/* Three forms, special case for zero
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   398
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   399
		 *   Latvian */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   400
		case 3:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   401
			return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
9229
7fa9ce47e9c0 (svn r12417) -Fix: Add a new plural rule for Icelandic.
maedhros
parents: 8941
diff changeset
   402
9231
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   403
		/* Three forms, special case for one and two
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   404
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   405
		 *   Gaelige (Irish) */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   406
		case 4:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   407
			return n == 1 ? 0 : n == 2 ? 1 : 2;
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   408
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   409
		/* Three forms, special case for numbers ending in 1[2-9]
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   410
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   411
		 *   Lithuanian */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   412
		case 5:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   413
			return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   414
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   415
		/* Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   416
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   417
		 *   Croatian, Czech, Russian, Slovak, Ukrainian */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   418
		case 6:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   419
			return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   420
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   421
		/* Three forms, special case for one and some numbers ending in 2, 3, or 4
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   422
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   423
		 *   Polish */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   424
		case 7:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   425
			return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   426
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   427
		/* Four forms, special case for one and all numbers ending in 02, 03, or 04
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   428
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   429
		 *   Slovenian */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   430
		case 8:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   431
			return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   432
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   433
		/* Two forms; singular used for everything ending in 1 but not in 11.
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   434
		 * Used in:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   435
		 *   Icelandic */
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   436
		case 9:
5f6249699caf (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 9229
diff changeset
   437
			return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   438
	}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   439
}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   440
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   441
static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   442
{
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   443
	//<NUM> {Length of each string} {each string}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   444
	uint n = (byte)*b++;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6916
diff changeset
   445
	uint pos, i, mylen = 0, mypos = 0;
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   446
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   447
	for (i = pos = 0; i != n; i++) {
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   448
		uint len = (byte)*b++;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   449
		if (i == form) {
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   450
			mypos = pos;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   451
			mylen = len;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   452
		}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   453
		pos += len;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   454
	}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   455
	*dstlen = mylen;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   456
	memcpy(dst, b + mypos, mylen);
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   457
	return b + pos;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   458
}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   459
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   460
struct Units {
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   461
	int s_m;           ///< Multiplier for velocity
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   462
	int s_s;           ///< Shift for velocity
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   463
	StringID velocity; ///< String for velocity
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   464
	int p_m;           ///< Multiplier for power
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   465
	int p_s;           ///< Shift for power
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   466
	StringID power;    ///< String for velocity
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   467
	int w_m;           ///< Multiplier for weight
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   468
	int w_s;           ///< Shift for weight
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   469
	StringID s_weight; ///< Short string for weight
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   470
	StringID l_weight; ///< Long string for weight
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   471
	int v_m;           ///< Multiplier for volume
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   472
	int v_s;           ///< Shift for volume
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   473
	StringID s_volume; ///< Short string for volume
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   474
	StringID l_volume; ///< Long string for volume
3489
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   475
	int f_m;           ///< Multiplier for force
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   476
	int f_s;           ///< Shift for force
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   477
	StringID force;    ///< String for force
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   478
};
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   479
3489
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   480
/* Unit conversions */
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   481
static const Units units[] = {
5653
5d95f08eb4b9 (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   482
	{ // Imperial (Original, mph, hp, metric ton, litre, kN)
6125
492a1c0440af (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: 6065
diff changeset
   483
		   1,  0, STR_UNITS_VELOCITY_IMPERIAL,
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   484
		   1,  0, STR_UNITS_POWER_IMPERIAL,
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   485
		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   486
		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
5653
5d95f08eb4b9 (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   487
		   1,  0, STR_UNITS_FORCE_SI,
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   488
	},
5653
5d95f08eb4b9 (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   489
	{ // Metric (km/h, hp, metric ton, litre, kN)
6125
492a1c0440af (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: 6065
diff changeset
   490
		 103,  6, STR_UNITS_VELOCITY_METRIC,
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   491
		   1,  0, STR_UNITS_POWER_METRIC,
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   492
		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   493
		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
5653
5d95f08eb4b9 (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   494
		   1,  0, STR_UNITS_FORCE_SI,
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   495
	},
3489
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   496
	{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton)
6125
492a1c0440af (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: 6065
diff changeset
   497
		1831, 12, STR_UNITS_VELOCITY_SI,
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   498
		 764, 10, STR_UNITS_POWER_SI,
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   499
		1000,  0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
3485
a67571100234 (svn r4336) Fix units conversion of volume for SI
peter1138
parents: 3477
diff changeset
   500
		   1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
3489
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   501
		   1,  0, STR_UNITS_FORCE_SI,
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   502
	},
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   503
};
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   504
10134
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   505
/**
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   506
 * Convert the given (internal) speed to the display speed.
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   507
 * @param speed the speed to convert
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   508
 * @return the converted speed.
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   509
 */
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   510
uint ConvertSpeedToDisplaySpeed(uint speed)
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   511
{
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   512
 return (speed * units[_settings_game.locale.units].s_m) >> units[_settings_game.locale.units].s_s;
10134
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   513
}
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   514
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   515
/**
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   516
 * Convert the given display speed to the (internal) speed.
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   517
 * @param speed the speed to convert
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   518
 * @return the converted speed.
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   519
 */
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   520
uint ConvertDisplaySpeedToSpeed(uint speed)
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   521
{
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   522
	return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m;
10134
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   523
}
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   524
7498
ce6588257e8d (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: 7492
diff changeset
   525
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
   526
{
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   527
	WChar b;
7498
ce6588257e8d (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: 7492
diff changeset
   528
	const int64 *argv_orig = argv;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   529
	uint modifier = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   531
	while ((b = Utf8Consume(&str)) != '\0') {
8112
f432a920f3b7 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7931
diff changeset
   532
		if (SCC_NEWGRF_FIRST <= b && b <= SCC_NEWGRF_LAST) {
f432a920f3b7 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7931
diff changeset
   533
			/* We need to pass some stuff as it might be modified; oh boy. */
f432a920f3b7 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7931
diff changeset
   534
			b = RemapNewGRFStringControlCode(b, &buff, &str, (int64*)argv);
f432a920f3b7 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7931
diff changeset
   535
			if (b == 0) continue;
f432a920f3b7 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7931
diff changeset
   536
		}
f432a920f3b7 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7931
diff changeset
   537
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   538
		switch (b) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   539
			case SCC_SETX: // {SETX}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   540
				if (buff + Utf8CharLen(SCC_SETX) + 1 < last) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   541
					buff += Utf8Encode(buff, SCC_SETX);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   542
					*buff++ = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   543
				}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   544
				break;
2410
d1fae093e768 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   545
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   546
			case SCC_SETXY: // {SETXY}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   547
				if (buff + Utf8CharLen(SCC_SETXY) + 2 < last) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   548
					buff += Utf8Encode(buff, SCC_SETXY);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   549
					*buff++ = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   550
					*buff++ = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   551
				}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   552
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   553
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   554
			case SCC_STRING_ID: // {STRINL}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   555
				buff = GetStringWithArgs(buff, Utf8Consume(&str), argv, last);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   556
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   557
11157
a0173588b15e (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: 10998
diff changeset
   558
			case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
a0173588b15e (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: 10998
diff changeset
   559
				const char *str = (const char*)GetInt64(&argv);
a0173588b15e (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: 10998
diff changeset
   560
				buff = FormatString(buff, str, argv, casei, last);
a0173588b15e (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: 10998
diff changeset
   561
				break;
a0173588b15e (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: 10998
diff changeset
   562
			}
a0173588b15e (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: 10998
diff changeset
   563
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   564
			case SCC_DATE_LONG: // {DATE_LONG}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   565
				buff = FormatYmdString(buff, GetInt32(&argv), last);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   566
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   567
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   568
			case SCC_DATE_SHORT: // {DATE_SHORT}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   569
				buff = FormatMonthAndYear(buff, GetInt32(&argv), last);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   570
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   571
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   572
			case SCC_VELOCITY: {// {VELOCITY}
7498
ce6588257e8d (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: 7492
diff changeset
   573
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   574
				assert(_settings_game.locale.units < lengthof(units));
10134
9a2cfea36caf (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 9286
diff changeset
   575
				args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv));
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   576
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].velocity), args, modifier >> 24, last);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   577
				modifier = 0;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   578
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   579
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   580
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   581
			case SCC_CURRENCY_COMPACT: /* {CURRCOMPACT} */
7490
3550f7e59b2e (svn r10250) -Fix: money is always 64 bits, so always parse those 64 bits.
rubidium
parents: 7452
diff changeset
   582
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
				break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   584
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   585
			case SCC_REVISION: /* {REV} */
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   586
				buff = strecpy(buff, _openttd_revision, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
				break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   588
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   589
			case SCC_CARGO_SHORT: { /* {SHORTCARGO} */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   590
				/* Short description of cargotypes. Layout:
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   591
				 * 8-bit = cargo type
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   592
				 * 16-bit = cargo count */
6417
26acff62d001 (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: 6414
diff changeset
   593
				StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   594
				switch (cargo_str) {
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   595
					case STR_TONS: {
7498
ce6588257e8d (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: 7492
diff changeset
   596
						int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   597
						assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   598
						args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   599
						buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   600
						modifier = 0;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   601
						break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   602
					}
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   603
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   604
					case STR_LITERS: {
7498
ce6588257e8d (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: 7492
diff changeset
   605
						int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   606
						assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   607
						args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   608
						buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, modifier >> 24, last);
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   609
						modifier = 0;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   610
						break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   611
					}
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   612
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   613
					default:
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   614
						if (cargo_str >= 0xE000 && cargo_str < 0xF800) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   615
							/* NewGRF strings from Action 4 use a different format here,
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   616
							 * of e.g. "x tonnes of coal", so process accordingly. */
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   617
							buff = GetStringWithArgs(buff, cargo_str, argv++, last);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   618
						} else {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   619
							buff = FormatCommaNumber(buff, GetInt32(&argv), last);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   620
							buff = strecpy(buff, " ", last);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   621
							buff = strecpy(buff, GetStringPtr(cargo_str), last);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   622
						}
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   623
						break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   624
				}
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   625
			} break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   626
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   627
			case SCC_STRING1: { /* {STRING1} */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   628
				/* String that consumes ONE argument */
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   629
				uint str = modifier + GetInt32(&argv);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   630
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1), last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   631
				modifier = 0;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   632
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   633
			}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   634
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   635
			case SCC_STRING2: { /* {STRING2} */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   636
				/* String that consumes TWO arguments */
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   637
				uint str = modifier + GetInt32(&argv);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   638
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2), last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   639
				modifier = 0;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   640
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   641
			}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   642
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   643
			case SCC_STRING3: { /* {STRING3} */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   644
				/* String that consumes THREE arguments */
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   645
				uint str = modifier + GetInt32(&argv);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   646
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3), last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   647
				modifier = 0;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   648
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   649
			}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   650
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   651
			case SCC_STRING4: { /* {STRING4} */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   652
				/* String that consumes FOUR arguments */
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   653
				uint str = modifier + GetInt32(&argv);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   654
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4), last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   655
				modifier = 0;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   656
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   657
			}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   658
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   659
			case SCC_STRING5: { /* {STRING5} */
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   660
				/* String that consumes FIVE arguments */
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   661
				uint str = modifier + GetInt32(&argv);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   662
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5), last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   663
				modifier = 0;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   664
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   665
			}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   666
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   667
			case SCC_STATION_FEATURES: { /* {STATIONFEATURES} */
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   668
				buff = StationGetSpecialString(buff, GetInt32(&argv), last);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   669
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   670
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   672
			case SCC_INDUSTRY_NAME: { /* {INDUSTRY} */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 2966
diff changeset
   673
				const Industry* i = GetIndustry(GetInt32(&argv));
7498
ce6588257e8d (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: 7492
diff changeset
   674
				int64 args[2];
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   675
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   676
				/* industry not valid anymore? */
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7882
diff changeset
   677
				if (!i->IsValid()) break;
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   678
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   679
				/* First print the town name and the industry type name
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   680
				 * The string STR_INDUSTRY_PATTERN controls the formatting */
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   681
				args[0] = i->town->index;
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4920
diff changeset
   682
				args[1] = GetIndustrySpec(i->type)->name;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   683
				buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24, last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   684
				modifier = 0;
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   685
				break;
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   686
			}
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   687
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   688
			case SCC_VOLUME: { // {VOLUME}
7498
ce6588257e8d (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: 7492
diff changeset
   689
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   690
				assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   691
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   692
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, modifier >> 24, last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   693
				modifier = 0;
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   694
				break;
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   695
			}
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   696
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   697
			case SCC_GENDER_LIST: { // {G 0 Der Die Das}
8941
f93c669d3ca6 (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: 8819
diff changeset
   698
				const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   699
				int len;
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   700
				int gender = 0;
7907
5e026fa6089a (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: 7889
diff changeset
   701
				if (s != NULL) {
5e026fa6089a (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: 7889
diff changeset
   702
					wchar_t c = Utf8Consume(&s);
5e026fa6089a (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: 7889
diff changeset
   703
					/* Switch case is always put before genders, so remove those bits */
5e026fa6089a (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: 7889
diff changeset
   704
					if (c == SCC_SWITCH_CASE) {
5e026fa6089a (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: 7889
diff changeset
   705
						/* Skip to the last (i.e. default) case */
5e026fa6089a (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: 7889
diff changeset
   706
						for (uint num = (byte)*s++; num != 0; num--) s += 3 + (s[1] << 8) + s[2];
5e026fa6089a (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: 7889
diff changeset
   707
5e026fa6089a (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: 7889
diff changeset
   708
						c = Utf8Consume(&s);
5e026fa6089a (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: 7889
diff changeset
   709
					}
5e026fa6089a (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: 7889
diff changeset
   710
					/* Does this string have a gender, if so, set it */
5e026fa6089a (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: 7889
diff changeset
   711
					if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
5e026fa6089a (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: 7889
diff changeset
   712
				}
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   713
				str = ParseStringChoice(str, gender, buff, &len);
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   714
				buff += len;
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   715
				break;
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   716
			}
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   717
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   718
			case SCC_DATE_TINY: { // {DATE_TINY}
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   719
				buff = FormatTinyDate(buff, GetInt32(&argv), last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   720
				break;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   721
			}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   722
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   723
			case SCC_CARGO: { // {CARGO}
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   724
				/* Layout now is:
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   725
				 *   8bit   - cargo type
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   726
				 *   16-bit - cargo count */
4898
68560c75ec28 (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
   727
				CargoID cargo = GetInt32(&argv);
7889
f167f5959c24 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7886
diff changeset
   728
				StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : GetCargo(cargo)->quantifier;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   729
				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   730
				break;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   731
			}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   732
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   733
			case SCC_POWER: { // {POWER}
7498
ce6588257e8d (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: 7492
diff changeset
   734
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   735
				assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   736
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].p_m >> units[_settings_game.locale.units].p_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   737
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].power), args, modifier >> 24, last);
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   738
				modifier = 0;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   739
				break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   740
			}
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   741
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   742
			case SCC_VOLUME_SHORT: { // {VOLUME_S}
7498
ce6588257e8d (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: 7492
diff changeset
   743
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   744
				assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   745
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   746
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_volume), args, modifier >> 24, last);
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   747
				modifier = 0;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   748
				break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   749
			}
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   750
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   751
			case SCC_WEIGHT: { // {WEIGHT}
7498
ce6588257e8d (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: 7492
diff changeset
   752
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   753
				assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   754
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   755
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   756
				modifier = 0;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   757
				break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   758
			}
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   759
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   760
			case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
7498
ce6588257e8d (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: 7492
diff changeset
   761
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   762
				assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   763
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   764
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_weight), args, modifier >> 24, last);
3342
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   765
				modifier = 0;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   766
				break;
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   767
			}
0de5e6997611 (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   768
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   769
			case SCC_FORCE: { // {FORCE}
7498
ce6588257e8d (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: 7492
diff changeset
   770
				int64 args[1];
10835
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   771
				assert(_settings_game.locale.units < lengthof(units));
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   772
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].f_m >> units[_settings_game.locale.units].f_s;
976b9d25c2be (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 10775
diff changeset
   773
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].force), args, modifier >> 24, last);
3489
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   774
				modifier = 0;
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   775
				break;
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   776
			}
1a4ffb2bc0f4 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   777
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   778
			case SCC_SKIP: // {SKIP}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   779
				argv++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   780
				break;
2410
d1fae093e768 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   781
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   782
			/* This sets up the gender for the string.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   783
			 * We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   784
			case SCC_GENDER_INDEX: // {GENDER 0}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   785
				str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   786
				break;
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2548
diff changeset
   787
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   788
			case SCC_STRING: {// {STRING}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   789
				uint str = modifier + GetInt32(&argv);
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   790
				/* WARNING. It's prohibited for the included string to consume any arguments.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   791
				 * For included strings that consume argument, you should use STRING1, STRING2 etc.
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   792
				 * To debug stuff you can set argv to NULL and it will tell you */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   793
				buff = GetStringWithArgs(buff, str, argv, last);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   794
				modifier = 0;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   795
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   796
			}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   797
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   798
			case SCC_COMMA: // {COMMA}
7852
d2491d19f323 (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: 7844
diff changeset
   799
				buff = FormatCommaNumber(buff, GetInt64(&argv), last);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   800
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   801
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   802
			case SCC_ARG_INDEX: // Move argument pointer
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   803
				argv = argv_orig + (byte)*str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   804
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   805
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   806
			case SCC_PLURAL_LIST: { // {P}
7852
d2491d19f323 (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: 7844
diff changeset
   807
				int64 v = argv_orig[(byte)*str++]; // contains the number that determines plural
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   808
				int len;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   809
				str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   810
				buff += len;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   811
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   812
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   813
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   814
			case SCC_NUM: // {NUM}
7852
d2491d19f323 (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: 7844
diff changeset
   815
				buff = FormatNoCommaNumber(buff, GetInt64(&argv), last);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   816
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   817
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   818
			case SCC_CURRENCY: // {CURRENCY}
7490
3550f7e59b2e (svn r10250) -Fix: money is always 64 bits, so always parse those 64 bits.
rubidium
parents: 7452
diff changeset
   819
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   820
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   821
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   822
			case SCC_WAYPOINT_NAME: { // {WAYPOINT}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   823
				Waypoint *wp = GetWaypoint(GetInt32(&argv));
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   824
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   825
				if (!wp->IsValid()) { // waypoint doesn't exist anymore
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   826
					buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   827
				} else if (wp->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   828
					buff = strecpy(buff, wp->name, last);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   829
				} else {
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   830
					int64 temp[2];
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   831
					temp[0] = wp->town_index;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   832
					temp[1] = wp->town_cn + 1;
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   833
					StringID str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   834
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   835
					buff = GetStringWithArgs(buff, str, temp, last);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   836
				}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   837
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
			}
1097
653c846fb5d9 (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   839
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   840
			case SCC_STATION_NAME: { // {STATION}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   841
				const Station* st = GetStation(GetInt32(&argv));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   842
6322
3d191e6e89bc (svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents: 6125
diff changeset
   843
				if (!st->IsValid()) { // station doesn't exist anymore
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   844
					buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last);
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   845
				} else if (st->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   846
					buff = strecpy(buff, st->name, last);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   847
				} else {
7551
9ae828d83ff2 (svn r10320) -Fix [FS#278]: one could only build a limited number of stations before one had to rename them.
rubidium
parents: 7547
diff changeset
   848
					int64 temp[3];
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   849
					temp[0] = STR_TOWN;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   850
					temp[1] = st->town->index;
7551
9ae828d83ff2 (svn r10320) -Fix [FS#278]: one could only build a limited number of stations before one had to rename them.
rubidium
parents: 7547
diff changeset
   851
					temp[2] = st->index;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   852
					buff = GetStringWithArgs(buff, st->string_id, temp, last);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   853
				}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   854
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   855
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   856
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   857
			case SCC_TOWN_NAME: { // {TOWN}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   858
				const Town* t = GetTown(GetInt32(&argv));
7498
ce6588257e8d (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: 7492
diff changeset
   859
				int64 temp[1];
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   860
7882
64cdb1d52f16 (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents: 7878
diff changeset
   861
				assert(t->IsValid());
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   862
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   863
				temp[0] = t->townnameparts;
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   864
				uint32 grfid = t->townnamegrfid;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   865
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   866
				if (t->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   867
					buff = strecpy(buff, t->name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   868
				} else if (grfid == 0) {
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   869
					/* Original town name */
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   870
					buff = GetStringWithArgs(buff, t->townnametype, temp, last);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   871
				} else {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   872
					/* Newgrf town name */
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   873
					if (GetGRFTownName(grfid) != NULL) {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   874
						/* The grf is loaded */
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   875
						buff = GRFTownNameGenerate(buff, t->townnamegrfid, t->townnametype, t->townnameparts, last);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   876
					} else {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   877
						/* Fallback to english original */
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   878
						buff = GetStringWithArgs(buff, SPECSTR_TOWNNAME_ENGLISH, temp, last);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   879
					}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7425
diff changeset
   880
				}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   881
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   882
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   883
7139
4ae3ab180d05 (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: 6988
diff changeset
   884
			case SCC_GROUP_NAME: { // {GROUP}
4ae3ab180d05 (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: 6988
diff changeset
   885
				const Group *g = GetGroup(GetInt32(&argv));
4ae3ab180d05 (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: 6988
diff changeset
   886
7878
70e8283207cd (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7852
diff changeset
   887
				assert(g->IsValid());
7139
4ae3ab180d05 (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: 6988
diff changeset
   888
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   889
				if (g->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   890
					buff = strecpy(buff, g->name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   891
				} else {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   892
					int64 args[1];
7139
4ae3ab180d05 (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: 6988
diff changeset
   893
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   894
					args[0] = g->index;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   895
					buff = GetStringWithArgs(buff, STR_GROUP_NAME_FORMAT, args, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   896
				}
7139
4ae3ab180d05 (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: 6988
diff changeset
   897
				break;
4ae3ab180d05 (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: 6988
diff changeset
   898
			}
4ae3ab180d05 (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: 6988
diff changeset
   899
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
   900
			case SCC_ENGINE_NAME: { // {ENGINE}
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
   901
				EngineID engine = (EngineID)GetInt32(&argv);
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   902
				const Engine *e = GetEngine(engine);
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
   903
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   904
				if (e->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   905
					buff = strecpy(buff, e->name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   906
				} else {
10382
d1d4452acbfc (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: 10261
diff changeset
   907
					buff = GetStringWithArgs(buff, e->info.string_id, NULL, last);
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   908
				}
7555
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
   909
				break;
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
   910
			}
e20900912fa2 (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7554
diff changeset
   911
7545
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   912
			case SCC_VEHICLE_NAME: { // {VEHICLE}
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   913
				const Vehicle *v = GetVehicle(GetInt32(&argv));
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   914
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   915
				if (v->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   916
					buff = strecpy(buff, v->name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   917
				} else {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   918
					int64 args[1];
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   919
					args[0] = v->unitnumber;
7545
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   920
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   921
					StringID str;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   922
					switch (v->type) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   923
						default: NOT_REACHED();
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   924
						case VEH_TRAIN:    str = STR_SV_TRAIN_NAME; break;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   925
						case VEH_ROAD:     str = STR_SV_ROADVEH_NAME; break;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   926
						case VEH_SHIP:     str = STR_SV_SHIP_NAME; break;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   927
						case VEH_AIRCRAFT: str = STR_SV_AIRCRAFT_NAME; break;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   928
					}
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   929
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   930
					buff = GetStringWithArgs(buff, str, args, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   931
				}
7545
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   932
				break;
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   933
			}
9a4834d48970 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7502
diff changeset
   934
7552
064d734e9900 (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7551
diff changeset
   935
			case SCC_SIGN_NAME: { // {SIGN}
064d734e9900 (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7551
diff changeset
   936
				const Sign *si = GetSign(GetInt32(&argv));
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   937
				if (si->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   938
					buff = strecpy(buff, si->name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   939
				} else {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   940
					buff = GetStringWithArgs(buff, STR_280A_SIGN, NULL, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   941
				}
7552
064d734e9900 (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7551
diff changeset
   942
				break;
064d734e9900 (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7551
diff changeset
   943
			}
064d734e9900 (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7551
diff changeset
   944
7554
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   945
			case SCC_COMPANY_NAME: { // {COMPANY}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   946
				const Player *p = GetPlayer((PlayerID)GetInt32(&argv));
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   947
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   948
				if (p->name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   949
					buff = strecpy(buff, p->name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   950
				} else {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   951
					int64 args[1];
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   952
					args[0] = p->name_2;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   953
					buff = GetStringWithArgs(buff, p->name_1, args, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   954
				}
7554
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   955
				break;
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   956
			}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   957
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   958
			case SCC_COMPANY_NUM: { // {COMPANYNUM}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   959
				PlayerID player = (PlayerID)GetInt32(&argv);
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   960
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   961
				/* Nothing is added for AI or inactive players */
11161
7d0fac8f14cd (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 11157
diff changeset
   962
				if (IsHumanPlayer(player) && IsValidPlayerID(player)) {
7554
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   963
					int64 args[1];
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   964
					args[0] = player + 1;
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   965
					buff = GetStringWithArgs(buff, STR_7002_PLAYER, args, last);
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   966
				}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   967
				break;
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   968
			}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   969
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   970
			case SCC_PLAYER_NAME: { // {PLAYERNAME}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   971
				const Player *p = GetPlayer((PlayerID)GetInt32(&argv));
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   972
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   973
				if (p->president_name != NULL) {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   974
					buff = strecpy(buff, p->president_name, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   975
				} else {
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   976
					int64 args[1];
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   977
					args[0] = p->president_name_2;
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   978
					buff = GetStringWithArgs(buff, p->president_name_1, args, last);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
   979
				}
7554
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   980
				break;
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   981
			}
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7552
diff changeset
   982
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   983
			case SCC_SETCASE: { // {SETCASE}
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   984
				/* This is a pseudo command, it's outputted when someone does {STRING.ack}
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   985
				 * The modifier is added to all subsequent GetStringWithArgs that accept the modifier. */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   986
				modifier = (byte)*str++ << 24;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   987
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   988
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   989
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   990
			case SCC_SWITCH_CASE: { // {Used to implement case switching}
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   991
				/* <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   992
				 * Each LEN is printed using 2 bytes in big endian order. */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   993
				uint num = (byte)*str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   994
				while (num) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   995
					if ((byte)str[0] == casei) {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
   996
						/* Found the case, adjust str pointer and continue */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   997
						str += 3;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   998
						break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   999
					}
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1000
					/* Otherwise skip to the next case */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1001
					str += 3 + (str[1] << 8) + str[2];
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1002
					num--;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1003
				}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1004
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1005
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1006
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1007
			default:
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1008
				if (buff + Utf8CharLen(b) < last) buff += Utf8Encode(buff, b);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1009
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	}
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1012
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1017
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
  1018
{
10261
b3e7149e3d81 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 10254
diff changeset
  1019
	if ((x & FACIL_TRAIN)      && (buff + Utf8CharLen(SCC_TRAIN) < last)) buff += Utf8Encode(buff, SCC_TRAIN);
b3e7149e3d81 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 10254
diff changeset
  1020
	if ((x & FACIL_TRUCK_STOP) && (buff + Utf8CharLen(SCC_LORRY) < last)) buff += Utf8Encode(buff, SCC_LORRY);
b3e7149e3d81 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 10254
diff changeset
  1021
	if ((x & FACIL_BUS_STOP)   && (buff + Utf8CharLen(SCC_BUS)   < last)) buff += Utf8Encode(buff, SCC_BUS);
b3e7149e3d81 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 10254
diff changeset
  1022
	if ((x & FACIL_AIRPORT)    && (buff + Utf8CharLen(SCC_PLANE) < last)) buff += Utf8Encode(buff, SCC_PLANE);
b3e7149e3d81 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 10254
diff changeset
  1023
	if ((x & FACIL_DOCK)       && (buff + Utf8CharLen(SCC_SHIP)  < last)) buff += Utf8Encode(buff, SCC_SHIP);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1024
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1028
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last)
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1029
{
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1030
	char name[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
4920
de739ffd31a4 (svn r6896) - Fix (r6895): Supply last position of the correct buffer *again*
peter1138
parents: 4919
diff changeset
  1032
	_town_name_generators[ind](name, seed, lastof(name));
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1033
	return strecpy(buff, name, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
2650
8caa93e39375 (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
  1036
static const char* const _silly_company_names[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
	"Bloggs Brothers",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	"Tiny Transport Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
	"Express Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	"Comfy-Coach & Co.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
	"Crush & Bump Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	"Broken & Late Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
	"Sam Speedy & Son",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
	"Supersonic Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	"Mike's Motors",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
	"Lightning International",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	"Pannik & Loozit Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
	"Inter-City Transport",
2650
8caa93e39375 (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
  1049
	"Getout & Pushit Ltd."
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
2650
8caa93e39375 (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
  1052
static const char* const _surname_list[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	"Adams",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	"Allan",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	"Baker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
	"Bigwig",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	"Black",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	"Bloggs",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	"Brown",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	"Campbell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	"Gordon",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	"Hamilton",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	"Hawthorn",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
	"Higgins",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	"Green",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	"Gribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	"Jones",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	"McAlpine",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	"MacDonald",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
	"McIntosh",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	"Muir",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
	"Murphy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
	"Nelson",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	"O'Donnell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
	"Parker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	"Phillips",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	"Pilkington",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	"Quigley",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
	"Sharkey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	"Thomson",
2650
8caa93e39375 (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
  1081
	"Watkins"
8caa93e39375 (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
  1082
};
8caa93e39375 (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
  1083
8caa93e39375 (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
  1084
static const char* const _silly_surname_list[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	"Grumpy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	"Dozy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
	"Speedy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
	"Nosey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	"Dribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
	"Mushroom",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	"Cabbage",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	"Sniffle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	"Fishy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	"Swindle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	"Sneaky",
2650
8caa93e39375 (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
  1096
	"Nutkins"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
1312
8defbb525d09 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1099
static const char _initial_name_letters[] = {
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1100
	'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1101
	'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
  1102
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1104
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
  1105
{
2650
8caa93e39375 (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
  1106
	const char* const* base;
8caa93e39375 (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
  1107
	uint num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
10775
7061477bfbcf (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: 10707
diff changeset
  1109
	if (_settings_game.game_creation.landscape == LT_TOYLAND) {
2650
8caa93e39375 (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
  1110
		base = _silly_surname_list;
8caa93e39375 (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
  1111
		num  = lengthof(_silly_surname_list);
8caa93e39375 (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
  1112
	} else {
8caa93e39375 (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
  1113
		base = _surname_list;
8caa93e39375 (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
  1114
		num  = lengthof(_surname_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1117
	buff = strecpy(buff, base[num * GB(arg, 16, 8) >> 8], last);
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1118
	buff = strecpy(buff, " & Co.", last);
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
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1123
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
  1124
{
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1125
	char initial[] = "?. ";
2650
8caa93e39375 (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
  1126
	const char* const* base;
8caa93e39375 (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
  1127
	uint num;
8caa93e39375 (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
  1128
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1130
	initial[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8];
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1131
	buff = strecpy(buff, initial, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
  1133
	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
  1134
	if (i < sizeof(_initial_name_letters)) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1135
		initial[0] = _initial_name_letters[i];
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1136
		buff = strecpy(buff, initial, last);
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
10775
7061477bfbcf (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: 10707
diff changeset
  1139
	if (_settings_game.game_creation.landscape == LT_TOYLAND) {
2650
8caa93e39375 (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
  1140
		base = _silly_surname_list;
8caa93e39375 (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
  1141
		num  = lengthof(_silly_surname_list);
8caa93e39375 (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
  1142
	} else {
8caa93e39375 (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
  1143
		base = _surname_list;
8caa93e39375 (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
  1144
		num  = lengthof(_surname_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1147
	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
  1148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
7498
ce6588257e8d (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: 7492
diff changeset
  1152
static char *GetSpecialPlayerNameString(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
  1153
{
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1154
	switch (ind) {
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1155
		case 1: // not used
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1156
			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
  1157
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1158
		case 2: // used for Foobar & Co company names
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1159
			return GenAndCoName(buff, GetInt32(&argv), last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1161
		case 3: // President name
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1162
			return GenPresidentName(buff, GetInt32(&argv), last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1164
		case 4: // song names
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1165
			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
  1166
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1168
	/* town name? */
10229
fba3f9fa44d7 (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 10134
diff changeset
  1169
	if (IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1170
		buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv), last);
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1171
		return strecpy(buff, " Transport", last);
0
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
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1174
	/* language name? */
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8424
diff changeset
  1175
	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
  1176
		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
1853
2c2f5699e75f (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
  1177
		return strecpy(buff,
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1178
			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
  1179
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1181
	/* resolution size? */
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8424
diff changeset
  1182
	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
  1183
		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1184
		buff += snprintf(
10983
e734f891d1f6 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents: 10839
diff changeset
  1185
			buff, last - buff + 1, "%dx%d", _resolutions[i].width, _resolutions[i].height
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1186
		);
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1187
		return buff;
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
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1190
	/* screenshot format name? */
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8424
diff changeset
  1191
	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
  1192
		int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1193
		return strecpy(buff, GetScreenshotFormatDesc(i), 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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
7394
75d35728b8b1 (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 7293
diff changeset
  1200
#ifdef ENABLE_NETWORK
7289
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1201
extern void SortNetworkLanguages();
7394
75d35728b8b1 (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 7293
diff changeset
  1202
#else /* ENABLE_NETWORK */
75d35728b8b1 (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 7293
diff changeset
  1203
static inline void SortNetworkLanguages() {}
75d35728b8b1 (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 7293
diff changeset
  1204
#endif /* ENABLE_NETWORK */
7289
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1205
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1206
bool ReadLanguagePack(int lang_index)
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1207
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	int tot_count, i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	size_t len;
1312
8defbb525d09 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1210
	char **langpack_offs;
8defbb525d09 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1211
	char *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1213
	LanguagePack *lang_pack = (LanguagePack*)ReadFileToMem(_dynlang.ent[lang_index].file, &len, 200000);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1214
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
	if (lang_pack == NULL) return false;
1319
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1216
	if (len < sizeof(LanguagePack) ||
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1217
			lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1218
			lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
		free(lang_pack);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
  1222
10998
04f58fa3dbb0 (svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents: 10983
diff changeset
  1223
#if TTD_ENDIAN == TTD_BIG_ENDIAN
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1224
	for (i = 0; i != 32; i++) {
2966
7f382cfeb93d (svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents: 2957
diff changeset
  1225
		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
  1226
	}
10998
04f58fa3dbb0 (svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents: 10983
diff changeset
  1227
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	tot_count = 0;
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1230
	for (i = 0; i != 32; i++) {
1319
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1231
		uint num = lang_pack->offsets[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
		_langtab_start[i] = tot_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
		_langtab_num[i] = num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
		tot_count += num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1237
	/* Allocate offsets */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
  1238
	langpack_offs = MallocT<char*>(tot_count);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1240
	/* Fill offsets */
1319
cd302ee91e27 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1241
	s = lang_pack->data;
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1242
	for (i = 0; i != tot_count; i++) {
1312
8defbb525d09 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1243
		len = (byte)*s;
1316
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1244
		*s++ = '\0'; // zero terminate the string before.
a7352de83a2b (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1245
		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
  1246
		langpack_offs[i] = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
		s += len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1250
	free(_langpack);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	_langpack = lang_pack;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1253
	free(_langpack_offs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
	_langpack_offs = langpack_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
6670
86c087999542 (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6646
diff changeset
  1256
	const char *c_file = strrchr(_dynlang.ent[lang_index].file, PATHSEPCHAR) + 1;
86c087999542 (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6646
diff changeset
  1257
	ttd_strlcpy(_dynlang.curr_file, c_file, lengthof(_dynlang.curr_file));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	_dynlang.curr = lang_index;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
  1260
	SetCurrentGrfLangID(_langpack->isocode);
7289
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1261
	SortNetworkLanguages();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
7844
fbecfb6e2c2b (svn r10711) -Fix [Win32]: take default language from current user's locale on Windows (In-)
KUDr
parents: 7812
diff changeset
  1265
/* Win32 implementation in win32.cpp. */
7931
855327e1ab53 (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: 7918
diff changeset
  1266
/* OS X implementation in os/macosx/macos.mm. */
855327e1ab53 (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: 7918
diff changeset
  1267
#if !(defined(WIN32) || defined(__APPLE__))
3329
992d1f7cb747 (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
  1268
/** Determine the current charset based on the environment
992d1f7cb747 (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
  1269
 * First check some default values, after this one we passed ourselves
992d1f7cb747 (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
  1270
 * and if none exist return the value for $LANG
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6685
diff changeset
  1271
 * @param param environment variable to check conditionally if default ones are not
3329
992d1f7cb747 (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
  1272
 *        set. Pass NULL if you don't want additional checks.
992d1f7cb747 (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
  1273
 * @return return string containing current charset, or NULL if not-determinable */
992d1f7cb747 (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
  1274
const char *GetCurrentLocale(const char *param)
992d1f7cb747 (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
  1275
{
992d1f7cb747 (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
  1276
	const char *env;
992d1f7cb747 (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
  1277
992d1f7cb747 (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
  1278
	env = getenv("LANGUAGE");
992d1f7cb747 (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
  1279
	if (env != NULL) return env;
992d1f7cb747 (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
  1280
992d1f7cb747 (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
  1281
	env = getenv("LC_ALL");
992d1f7cb747 (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
  1282
	if (env != NULL) return env;
992d1f7cb747 (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
  1283
992d1f7cb747 (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
  1284
	if (param != NULL) {
992d1f7cb747 (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
  1285
		env = getenv(param);
992d1f7cb747 (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
  1286
		if (env != NULL) return env;
992d1f7cb747 (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
  1287
	}
992d1f7cb747 (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
  1288
992d1f7cb747 (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
  1289
	return getenv("LANG");
992d1f7cb747 (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
  1290
}
10254
14e7c7ada607 (svn r12786) -Change: remove more function from functions.h.
rubidium
parents: 10250
diff changeset
  1291
#else
14e7c7ada607 (svn r12786) -Change: remove more function from functions.h.
rubidium
parents: 10250
diff changeset
  1292
const char *GetCurrentLocale(const char *param);
7931
855327e1ab53 (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: 7918
diff changeset
  1293
#endif /* !(defined(WIN32) || defined(__APPLE__)) */
3329
992d1f7cb747 (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
  1294
7289
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1295
int CDECL StringIDSorter(const void *a, const void *b)
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1296
{
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1297
	const StringID va = *(const StringID*)a;
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1298
	const StringID vb = *(const StringID*)b;
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1299
	char stra[512];
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1300
	char strb[512];
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1301
	GetString(stra, va, lastof(stra));
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1302
	GetString(strb, vb, lastof(strb));
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1303
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1304
	return strcmp(stra, strb);
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1305
}
d6a004877931 (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 7139
diff changeset
  1306
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1307
/**
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1308
 * Checks whether the given language is already found.
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1309
 * @param langs    languages we've found so fa
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1310
 * @param max      the length of the language list
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1311
 * @param language name of the language to check
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1312
 * @return true if and only if a language file with the same name has not been found
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1313
 */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1314
static bool UniqueLanguageFile(const Language *langs, uint max, const char *language)
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1315
{
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1316
	for (uint i = 0; i < max; i++) {
6670
86c087999542 (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6646
diff changeset
  1317
		const char *f_name = strrchr(langs[i].file, PATHSEPCHAR) + 1;
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1318
		if (strcmp(f_name, language) == 0) return false; // duplicates
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1319
	}
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1320
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1321
	return true;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1322
}
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1323
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1324
/**
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1325
 * Reads the language file header and checks compatability.
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1326
 * @param file the file to read
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1327
 * @param hdr  the place to write the header information to
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1328
 * @return true if and only if the language file is of a compatible version
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1329
 */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1330
static bool GetLanguageFileHeader(const char *file, LanguagePack *hdr)
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1331
{
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1332
	FILE *f = fopen(file, "rb");
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1333
	if (f == NULL) return false;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1334
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1335
	size_t read = fread(hdr, sizeof(*hdr), 1, f);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1336
	fclose(f);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1337
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1338
	return read == 1 &&
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1339
			hdr->ident == TO_LE32(LANGUAGE_PACK_IDENT) &&
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1340
			hdr->version == TO_LE32(LANGUAGE_PACK_VERSION);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1341
}
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1342
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1343
/**
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1344
 * Gets a list of languages from the given directory.
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1345
 * @param langs the list to write to
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1346
 * @param start the initial offset in the list
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1347
 * @param max   the length of the language list
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1348
 * @param path  the base directory to search in
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1349
 * @return the number of added languages
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1350
 */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1351
static int GetLanguageList(Language *langs, int start, int max, const char *path)
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1352
{
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1353
	int i = start;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1354
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1355
	DIR *dir = ttd_opendir(path);
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1356
	if (dir != NULL) {
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1357
		struct dirent *dirent;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1358
		while ((dirent = readdir(dir)) != NULL && i < max) {
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1359
			const char *d_name    = FS2OTTD(dirent->d_name);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1360
			const char *extension = strrchr(d_name, '.');
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1361
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1362
			/* Not a language file */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1363
			if (extension == NULL || strcmp(extension, ".lng") != 0) continue;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1364
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1365
			/* Filter any duplicate language-files, first-come first-serve */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1366
			if (!UniqueLanguageFile(langs, i, d_name)) continue;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1367
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1368
			langs[i].file = str_fmt("%s%s", path, d_name);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1369
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1370
			/* Check whether the file is of the correct version */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1371
			LanguagePack hdr;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1372
			if (!GetLanguageFileHeader(langs[i].file, &hdr)) {
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1373
				free(langs[i].file);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1374
				continue;
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1375
			}
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1376
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1377
			i++;
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1378
		}
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1379
		closedir(dir);
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1380
	}
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1381
	return i - start;
4219
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1382
}
4211284f29ec (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1383
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1384
/**
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1385
 * Make a list of the available language packs. put the data in
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1386
 * _dynlang struct.
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1387
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6484
diff changeset
  1388
void InitializeLanguagePacks()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
{
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1390
	Searchpath sp;
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1391
	Language files[MAX_LANG];
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1392
	uint language_count = 0;
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1393
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1394
	FOR_ALL_SEARCHPATHS(sp) {
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1395
		char path[MAX_PATH];
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1396
		FioAppendDirectory(path, lengthof(path), sp, LANG_DIR);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1397
		language_count += GetLanguageList(files, language_count, lengthof(files), path);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7394
diff changeset
  1398
	}
10839
a62547c31fdb (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: 10835
diff changeset
  1399
	if (language_count == 0) usererror("No available language packs (invalid versions?)");
2257
9cf0a4b8eadb (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1400
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1401
	/* Acquire the locale of the current system */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1402
	const char *lang = GetCurrentLocale("LC_MESSAGES");
4505
f87e0c7fdda1 (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
  1403
	if (lang == NULL) lang = "en_GB";
2257
9cf0a4b8eadb (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1404
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1405
	int chosen_language   = -1; ///< Matching the language in the configuartion file or the current locale
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1406
	int language_fallback = -1; ///< Using pt_PT for pt_BR locale when pt_BR is not available
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1407
	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
  1408
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1409
	DynamicLanguages *dl = &_dynlang;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1410
	dl->num = 0;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1411
	/* Fill the dynamic languages structures */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1412
	for (uint i = 0; i < language_count; i++) {
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1413
		/* File read the language header */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1414
		LanguagePack hdr;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1415
		if (!GetLanguageFileHeader(files[i].file, &hdr)) continue;
1321
938ec22ae6f7 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1416
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1417
		dl->ent[dl->num].file = files[i].file;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1418
		dl->ent[dl->num].name = strdup(hdr.name);
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1419
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1420
		/* We are trying to find a default language. The priority is by
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1421
		 * configuration file, local environment and last, if nothing found,
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1422
		 * english. If def equals -1, we have not picked a default language */
6670
86c087999542 (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6646
diff changeset
  1423
		const char *lang_file = strrchr(dl->ent[dl->num].file, PATHSEPCHAR) + 1;
86c087999542 (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6646
diff changeset
  1424
		if (strcmp(lang_file, dl->curr_file) == 0) chosen_language = dl->num;
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1425
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1426
		if (chosen_language == -1) {
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1427
			if (strcmp (hdr.isocode, "en_GB") == 0) en_GB_fallback    = dl->num;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1428
			if (strncmp(hdr.isocode, lang, 5) == 0) chosen_language   = dl->num;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1429
			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
  1430
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1432
		dl->num++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
10839
a62547c31fdb (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: 10835
diff changeset
  1435
	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
  1436
6646
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1437
	/* We haven't found the language in the config nor the one in the locale.
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1438
	 * Now we set it to one of the fallback languages */
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1439
	if (chosen_language == -1) {
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1440
		chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback;
0e3b3d315288 (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6574
diff changeset
  1441
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
10839
a62547c31fdb (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: 10835
diff changeset
  1443
	if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", dl->ent[chosen_language].file);
2075
7f0ca01392db (svn r2585) - Fix [Makefile]: some small cleanups, remove warnings, and add mersenne to makefile (Luca)
Darkvater
parents: 2070
diff changeset
  1444
}
8581
8e4e36a205fe (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: 8450
diff changeset
  1445
8e4e36a205fe (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: 8450
diff changeset
  1446
/**
8e4e36a205fe (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: 8450
diff changeset
  1447
 * Check whether the currently loaded language pack
8e4e36a205fe (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: 8450
diff changeset
  1448
 * uses characters that the currently loaded font
8e4e36a205fe (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: 8450
diff changeset
  1449
 * does not support. If this is the case an error
8e4e36a205fe (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: 8450
diff changeset
  1450
 * message will be shown in English. The error
8e4e36a205fe (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: 8450
diff changeset
  1451
 * message will not be localized because that would
8e4e36a205fe (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: 8450
diff changeset
  1452
 * mean it might use characters that are not in the
8e4e36a205fe (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: 8450
diff changeset
  1453
 * font, which is the whole reason this check has
8e4e36a205fe (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: 8450
diff changeset
  1454
 * been added.
8e4e36a205fe (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: 8450
diff changeset
  1455
 */
8e4e36a205fe (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: 8450
diff changeset
  1456
void CheckForMissingGlyphsInLoadedLanguagePack()
8e4e36a205fe (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: 8450
diff changeset
  1457
{
8697
8087ef158f01 (svn r11764) -Change: make the 'do characters exist in the current font file(s)' more robust.
rubidium
parents: 8640
diff changeset
  1458
	const Sprite *question_mark = GetGlyph(FS_NORMAL, '?');
8087ef158f01 (svn r11764) -Change: make the 'do characters exist in the current font file(s)' more robust.
rubidium
parents: 8640
diff changeset
  1459
8581
8e4e36a205fe (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: 8450
diff changeset
  1460
	for (uint i = 0; i != 32; i++) {
8e4e36a205fe (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: 8450
diff changeset
  1461
		for (uint j = 0; j < _langtab_num[i]; j++) {
8e4e36a205fe (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: 8450
diff changeset
  1462
			const char *string = _langpack_offs[_langtab_start[i] + j];
8e4e36a205fe (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: 8450
diff changeset
  1463
			WChar c;
8e4e36a205fe (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: 8450
diff changeset
  1464
			while ((c = Utf8Consume(&string)) != '\0') {
8e4e36a205fe (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: 8450
diff changeset
  1465
				if (c == SCC_SETX) {
8e4e36a205fe (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: 8450
diff changeset
  1466
					/*
8e4e36a205fe (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: 8450
diff changeset
  1467
					 * SetX is, together with SetXY as special character that
8e4e36a205fe (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: 8450
diff changeset
  1468
					 * uses the next (two) characters as data points. We have
8e4e36a205fe (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: 8450
diff changeset
  1469
					 * to skip those, otherwise the UTF8 reading will go
8e4e36a205fe (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: 8450
diff changeset
  1470
					 * haywire.
8e4e36a205fe (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: 8450
diff changeset
  1471
					 */
8e4e36a205fe (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: 8450
diff changeset
  1472
					string++;
8e4e36a205fe (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: 8450
diff changeset
  1473
				} else if (c == SCC_SETXY) {
8e4e36a205fe (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: 8450
diff changeset
  1474
					string += 2;
8697
8087ef158f01 (svn r11764) -Change: make the 'do characters exist in the current font file(s)' more robust.
rubidium
parents: 8640
diff changeset
  1475
				} else if (IsPrintable(c) && c != '?' && GetGlyph(FS_NORMAL, c) == question_mark) {
8581
8e4e36a205fe (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: 8450
diff changeset
  1476
					/*
8e4e36a205fe (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: 8450
diff changeset
  1477
					 * The character is printable, but not in the normal font.
8e4e36a205fe (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: 8450
diff changeset
  1478
					 * This is the case we were testing for. In this case we
8e4e36a205fe (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: 8450
diff changeset
  1479
					 * have to show the error. As we do not want the string to
8e4e36a205fe (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: 8450
diff changeset
  1480
					 * be translated by the translators, we 'force' it into the
8e4e36a205fe (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: 8450
diff changeset
  1481
					 * binary and 'load' it via a BindCString. To do this
8e4e36a205fe (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: 8450
diff changeset
  1482
					 * properly we have to set the color of the string,
8e4e36a205fe (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: 8450
diff changeset
  1483
					 * otherwise we end up with a lot of artefacts. The color
8e4e36a205fe (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: 8450
diff changeset
  1484
					 * 'character' might change in the future, so for safety
8e4e36a205fe (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: 8450
diff changeset
  1485
					 * we just Utf8 Encode it into the string, which takes
8e4e36a205fe (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: 8450
diff changeset
  1486
					 * exactly three characters, so it replaces the "XXX" with
8e4e36a205fe (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: 8450
diff changeset
  1487
					 * the color marker.
8e4e36a205fe (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: 8450
diff changeset
  1488
					 */
8698
3968b1da2966 (svn r11765) -Fix: compile warning (Roujin).
rubidium
parents: 8697
diff changeset
  1489
					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.");
8581
8e4e36a205fe (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: 8450
diff changeset
  1490
					Utf8Encode(err_str, SCC_YELLOW);
11157
a0173588b15e (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: 10998
diff changeset
  1491
					SetDParamStr(0, err_str);
a0173588b15e (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: 10998
diff changeset
  1492
					ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 0, 0);
8581
8e4e36a205fe (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: 8450
diff changeset
  1493
					return;
8e4e36a205fe (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: 8450
diff changeset
  1494
				}
8e4e36a205fe (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: 8450
diff changeset
  1495
			}
8e4e36a205fe (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: 8450
diff changeset
  1496
		}
8e4e36a205fe (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: 8450
diff changeset
  1497
	}
8e4e36a205fe (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: 8450
diff changeset
  1498
}
10250
e64ee7484b43 (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: 10229
diff changeset
  1499
e64ee7484b43 (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: 10229
diff changeset
  1500
e64ee7484b43 (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: 10229
diff changeset
  1501
/* --- Handling of saving/loading string IDs from old savegames --- */
e64ee7484b43 (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: 10229
diff changeset
  1502
e64ee7484b43 (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: 10229
diff changeset
  1503
/**
e64ee7484b43 (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: 10229
diff changeset
  1504
 * Remap a string ID from the old format to the new format
e64ee7484b43 (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: 10229
diff changeset
  1505
 * @param s StringID that requires remapping
e64ee7484b43 (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: 10229
diff changeset
  1506
 * @return translated ID
e64ee7484b43 (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: 10229
diff changeset
  1507
 */
e64ee7484b43 (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: 10229
diff changeset
  1508
StringID RemapOldStringID(StringID s)
e64ee7484b43 (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: 10229
diff changeset
  1509
{
e64ee7484b43 (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: 10229
diff changeset
  1510
	switch (s) {
e64ee7484b43 (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: 10229
diff changeset
  1511
		case 0x0006: return STR_SV_EMPTY;
e64ee7484b43 (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: 10229
diff changeset
  1512
		case 0x7000: return STR_SV_UNNAMED;
e64ee7484b43 (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: 10229
diff changeset
  1513
		case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH;
e64ee7484b43 (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: 10229
diff changeset
  1514
		case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH;
e64ee7484b43 (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: 10229
diff changeset
  1515
		case 0x8864: return STR_SV_TRAIN_NAME;
e64ee7484b43 (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: 10229
diff changeset
  1516
		case 0x902B: return STR_SV_ROADVEH_NAME;
e64ee7484b43 (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: 10229
diff changeset
  1517
		case 0x9830: return STR_SV_SHIP_NAME;
e64ee7484b43 (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: 10229
diff changeset
  1518
		case 0xA02F: return STR_SV_AIRCRAFT_NAME;
e64ee7484b43 (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: 10229
diff changeset
  1519
e64ee7484b43 (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: 10229
diff changeset
  1520
		default:
e64ee7484b43 (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: 10229
diff changeset
  1521
			if (IsInsideMM(s, 0x300F, 0x3030)) {
e64ee7484b43 (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: 10229
diff changeset
  1522
				return s - 0x300F + STR_SV_STNAME;
e64ee7484b43 (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: 10229
diff changeset
  1523
			} else {
e64ee7484b43 (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: 10229
diff changeset
  1524
				return s;
e64ee7484b43 (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: 10229
diff changeset
  1525
			}
e64ee7484b43 (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: 10229
diff changeset
  1526
	}
e64ee7484b43 (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: 10229
diff changeset
  1527
}
e64ee7484b43 (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: 10229
diff changeset
  1528
e64ee7484b43 (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: 10229
diff changeset
  1529
/** Location to load the old names to. */
e64ee7484b43 (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: 10229
diff changeset
  1530
char *_old_name_array = NULL;
e64ee7484b43 (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: 10229
diff changeset
  1531
e64ee7484b43 (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: 10229
diff changeset
  1532
/**
e64ee7484b43 (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: 10229
diff changeset
  1533
 * Copy and convert old custom names to UTF-8.
e64ee7484b43 (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: 10229
diff changeset
  1534
 * They were all stored in a 512 by 32 long string array and are
e64ee7484b43 (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: 10229
diff changeset
  1535
 * now stored with stations, waypoints and other places with names.
e64ee7484b43 (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: 10229
diff changeset
  1536
 * @param id the StringID of the custom name to clone.
e64ee7484b43 (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: 10229
diff changeset
  1537
 * @return the clones custom name.
e64ee7484b43 (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: 10229
diff changeset
  1538
 */
e64ee7484b43 (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: 10229
diff changeset
  1539
char *CopyFromOldName(StringID id)
e64ee7484b43 (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: 10229
diff changeset
  1540
{
e64ee7484b43 (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: 10229
diff changeset
  1541
	/* Is this name an (old) custom name? */
e64ee7484b43 (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: 10229
diff changeset
  1542
	if (GB(id, 11, 5) != 15) return NULL;
e64ee7484b43 (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: 10229
diff changeset
  1543
e64ee7484b43 (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: 10229
diff changeset
  1544
	if (CheckSavegameVersion(37)) {
e64ee7484b43 (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: 10229
diff changeset
  1545
		/* Old names were 32 characters long, so 128 characters should be
e64ee7484b43 (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: 10229
diff changeset
  1546
		 * plenty to allow for expansion when converted to UTF-8. */
e64ee7484b43 (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: 10229
diff changeset
  1547
		char tmp[128];
e64ee7484b43 (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: 10229
diff changeset
  1548
		const char *strfrom = &_old_name_array[32 * GB(id, 0, 9)];
e64ee7484b43 (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: 10229
diff changeset
  1549
		char *strto = tmp;
e64ee7484b43 (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: 10229
diff changeset
  1550
e64ee7484b43 (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: 10229
diff changeset
  1551
		for (; *strfrom != '\0'; strfrom++) {
e64ee7484b43 (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: 10229
diff changeset
  1552
			WChar c = (byte)*strfrom;
e64ee7484b43 (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: 10229
diff changeset
  1553
e64ee7484b43 (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: 10229
diff changeset
  1554
			/* Map from non-ISO8859-15 characters to UTF-8. */
e64ee7484b43 (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: 10229
diff changeset
  1555
			switch (c) {
e64ee7484b43 (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: 10229
diff changeset
  1556
				case 0xA4: c = 0x20AC; break; // Euro
e64ee7484b43 (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: 10229
diff changeset
  1557
				case 0xA6: c = 0x0160; break; // S with caron
e64ee7484b43 (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: 10229
diff changeset
  1558
				case 0xA8: c = 0x0161; break; // s with caron
e64ee7484b43 (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: 10229
diff changeset
  1559
				case 0xB4: c = 0x017D; break; // Z with caron
e64ee7484b43 (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: 10229
diff changeset
  1560
				case 0xB8: c = 0x017E; break; // z with caron
e64ee7484b43 (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: 10229
diff changeset
  1561
				case 0xBC: c = 0x0152; break; // OE ligature
e64ee7484b43 (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: 10229
diff changeset
  1562
				case 0xBD: c = 0x0153; break; // oe ligature
e64ee7484b43 (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: 10229
diff changeset
  1563
				case 0xBE: c = 0x0178; break; // Y with diaresis
e64ee7484b43 (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: 10229
diff changeset
  1564
				default: break;
e64ee7484b43 (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: 10229
diff changeset
  1565
			}
e64ee7484b43 (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: 10229
diff changeset
  1566
e64ee7484b43 (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: 10229
diff changeset
  1567
			/* Check character will fit into our buffer. */
e64ee7484b43 (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: 10229
diff changeset
  1568
			if (strto + Utf8CharLen(c) > lastof(tmp)) break;
e64ee7484b43 (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: 10229
diff changeset
  1569
e64ee7484b43 (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: 10229
diff changeset
  1570
			strto += Utf8Encode(strto, c);
e64ee7484b43 (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: 10229
diff changeset
  1571
		}
e64ee7484b43 (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: 10229
diff changeset
  1572
e64ee7484b43 (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: 10229
diff changeset
  1573
		/* Terminate the new string and copy it back to the name array */
e64ee7484b43 (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: 10229
diff changeset
  1574
		*strto = '\0';
e64ee7484b43 (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: 10229
diff changeset
  1575
e64ee7484b43 (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: 10229
diff changeset
  1576
		return strdup(tmp);
e64ee7484b43 (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: 10229
diff changeset
  1577
	} else {
e64ee7484b43 (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: 10229
diff changeset
  1578
		/* Name will already be in UTF-8. */
e64ee7484b43 (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: 10229
diff changeset
  1579
		return strdup(&_old_name_array[32 * GB(id, 0, 9)]);
e64ee7484b43 (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: 10229
diff changeset
  1580
	}
e64ee7484b43 (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: 10229
diff changeset
  1581
}
e64ee7484b43 (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: 10229
diff changeset
  1582
e64ee7484b43 (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: 10229
diff changeset
  1583
/**
e64ee7484b43 (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: 10229
diff changeset
  1584
 * Free the memory of the old names array.
e64ee7484b43 (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: 10229
diff changeset
  1585
 * Should be called once the old names have all been converted.
e64ee7484b43 (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: 10229
diff changeset
  1586
 */
e64ee7484b43 (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: 10229
diff changeset
  1587
void ResetOldNames()
e64ee7484b43 (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: 10229
diff changeset
  1588
{
e64ee7484b43 (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: 10229
diff changeset
  1589
	free(_old_name_array);
e64ee7484b43 (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: 10229
diff changeset
  1590
	_old_name_array = NULL;
e64ee7484b43 (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: 10229
diff changeset
  1591
}
e64ee7484b43 (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: 10229
diff changeset
  1592
e64ee7484b43 (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: 10229
diff changeset
  1593
/**
e64ee7484b43 (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: 10229
diff changeset
  1594
 * Initialize the old names table memory.
e64ee7484b43 (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: 10229
diff changeset
  1595
 */
e64ee7484b43 (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: 10229
diff changeset
  1596
void InitializeOldNames()
e64ee7484b43 (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: 10229
diff changeset
  1597
{
e64ee7484b43 (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: 10229
diff changeset
  1598
	free(_old_name_array);
e64ee7484b43 (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: 10229
diff changeset
  1599
	_old_name_array = CallocT<char>(512 * 32);
e64ee7484b43 (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: 10229
diff changeset
  1600
}
e64ee7484b43 (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: 10229
diff changeset
  1601
e64ee7484b43 (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: 10229
diff changeset
  1602
static void Load_NAME()
e64ee7484b43 (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: 10229
diff changeset
  1603
{
e64ee7484b43 (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: 10229
diff changeset
  1604
	int index;
e64ee7484b43 (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: 10229
diff changeset
  1605
e64ee7484b43 (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: 10229
diff changeset
  1606
	while ((index = SlIterateArray()) != -1) {
e64ee7484b43 (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: 10229
diff changeset
  1607
		SlArray(&_old_name_array[32 * index], SlGetFieldLength(), SLE_UINT8);
e64ee7484b43 (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: 10229
diff changeset
  1608
	}
e64ee7484b43 (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: 10229
diff changeset
  1609
}
e64ee7484b43 (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: 10229
diff changeset
  1610
e64ee7484b43 (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: 10229
diff changeset
  1611
extern const ChunkHandler _name_chunk_handlers[] = {
e64ee7484b43 (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: 10229
diff changeset
  1612
	{ 'NAME', NULL, Load_NAME, CH_ARRAY | CH_LAST},
e64ee7484b43 (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: 10229
diff changeset
  1613
};