strings.c
author bjarni
Sat, 03 Dec 2005 13:43:54 +0000
changeset 2712 f0b9526767d3
parent 2650 cec7c95d039d
child 2951 2de6d3a59743
permissions -rw-r--r--
(svn r3257) -Codechange: [OSX] removed the dynamic lib in bundle option (introduced in rev 3230)
it caused way more problems than it solved
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1853
diff changeset
     4
#include "openttd.h"
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents: 2257
diff changeset
     5
#include "currency.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
1317
3c90086ff34f (svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents: 1316
diff changeset
     7
#include "string.h"
1309
4403a69da4f8 (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
     8
#include "strings.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 504
diff changeset
     9
#include "table/strings.h"
1306
7768d8361d88 (svn r1810) Move town name generation declarations into a header of their own
tron
parents: 1102
diff changeset
    10
#include "namegen.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "vehicle.h"
6
e9b56d50aa99 (svn r7) -Feature [1003350] Euro introduction news item. (dominik81)
darkvater
parents: 0
diff changeset
    14
#include "news.h"
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 425
diff changeset
    15
#include "screenshot.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1376
diff changeset
    16
#include "waypoint.h"
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
    17
#include "industry.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    18
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
2201
f240b3c7e2ec (svn r2717) Move _userstring to strings.[ch]
tron
parents: 2186
diff changeset
    20
char _userstring[128];
f240b3c7e2ec (svn r2717) Move _userstring to strings.[ch]
tron
parents: 2186
diff changeset
    21
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    22
static char *StationGetSpecialString(char *buff, int x);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    23
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    24
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    26
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
663
80c66fd07863 (svn r1098) -Fix: server without revision build doesn't care about the client's version. Also moved all revision things where it belongs (network.c)
darkvater
parents: 659
diff changeset
    28
extern const char _openttd_revision[];
659
a9733f856cd0 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
    29
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    30
typedef struct LanguagePack {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	uint32 ident;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	uint32 version;			// 32-bits of auto generated version info which is basically a hash of strings.h
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	char name[32];			// the international name of this language
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	char own_name[32];	// the localized name of this language
1376
d4e1dd8eb7e5 (svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents: 1321
diff changeset
    35
	char isocode[16];	// the ISO code for the language (not country code)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	uint16 offsets[32];	// the offsets
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
    37
	byte plural_form;		// how to compute plural forms
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
    38
	byte pad[3];				// pad header to be a multiple of 4
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    39
	char data[VARARRAY_SIZE];
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    40
} LanguagePack;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    41
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    42
static char **_langpack_offs;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    43
static LanguagePack *_langpack;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    44
static uint _langtab_num[32]; // Offset into langpack offs
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    45
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
    46
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
    47
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = {
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    48
	{ /* LT_NORMAL */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    49
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    50
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    51
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    52
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    53
		STR_ITEMS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    54
		STR_CRATES,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    55
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    56
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    57
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    58
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    59
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    60
		STR_RES_OTHER
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    61
	},
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    62
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    63
	{ /* LT_HILLY */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    64
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    65
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    66
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    67
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    68
		STR_ITEMS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    69
		STR_CRATES,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    70
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    71
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    72
		STR_RES_OTHER,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    73
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    74
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    75
		STR_TONS
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    76
	},
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    77
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    78
	{ /* LT_DESERT */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    79
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    80
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    81
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    82
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    83
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    84
		STR_CRATES,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    85
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    86
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    87
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    88
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    89
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    90
		STR_TONS
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    91
	},
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    92
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    93
	{ /* LT_CANDY */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    94
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    95
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    96
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    97
		STR_NOTHING,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    98
		STR_NOTHING,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    99
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   100
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   101
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   102
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   103
		STR_NOTHING,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   104
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   105
		STR_NOTHING
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   106
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   110
// Read an int64 from the argv array.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   111
static inline int64 GetInt64(const int32 **argv)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   112
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   113
	int64 result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   114
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   115
	assert(argv);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   116
	result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   117
	(*argv)+=2;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   118
	return result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   119
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   120
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   121
// Read an int32 from the argv array.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   122
static inline int32 GetInt32(const int32 **argv)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   123
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   124
	assert(argv);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   125
	return *(*argv)++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   126
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   127
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   128
// Read an array from the argv array.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   129
static inline const int32 *GetArgvPtr(const int32 **argv, int n)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   130
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   131
	const int32 *result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   132
	assert(*argv);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   133
	result = *argv;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   134
	(*argv) += n;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   135
	return result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   136
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   137
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   138
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   139
#define NUM_BOUND_STRINGS 8
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   140
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   141
// Array to hold the bound strings.
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   142
static const char *_bound_strings[NUM_BOUND_STRINGS];
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   143
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   144
// This index is used to implement a "round-robin" allocating of
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   145
// slots for BindCString. NUM_BOUND_STRINGS slots are reserved.
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   146
// Which means that after NUM_BOUND_STRINGS calls to BindCString,
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   147
// the indices will be reused.
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   148
static int _bind_index;
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   149
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   150
static const char *GetStringPtr(StringID string)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   155
// The highest 8 bits of string contain the "case index".
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   156
// These 8 bits will only be set when FormatString wants to print
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   157
// the string in a different case. No one else except FormatString
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   158
// should set those bits.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   159
char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
{
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2131
diff changeset
   161
	uint index = GB(string,  0, 11);
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2131
diff changeset
   162
	uint tab   = GB(string, 11,  5);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
   164
	if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   166
	switch (tab) {
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   167
		case 4:
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   168
			if (index >= 0xC0)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   169
				return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv));
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   170
			break;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   171
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   172
		case 14:
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   173
			if (index >= 0xE4)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   174
				return GetSpecialPlayerNameString(buffr, index - 0xE4, argv);
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   175
			break;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   176
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   177
		// User defined name
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   178
		case 15:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   179
			return GetName(index, buffr);
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   180
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   181
		case 31:
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   182
			// dynamic strings. These are NOT to be passed through the formatter,
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   183
			// but passed through verbatim.
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   184
			if (index < (STR_SPEC_USERSTRING & 0x7FF)) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   185
				return strecpy(buffr, _bound_strings[index], NULL);
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   186
			}
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   187
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   188
			return FormatString(buffr, _userstring, NULL, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   191
	if (index >= _langtab_num[tab]) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   192
		error(
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   193
			"!String 0x%X is invalid. "
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   194
			"Probably because an old version of the .lng file.\n", string
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   195
		);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   196
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
   198
	return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   201
char *GetString(char *buffr, StringID string)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   202
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   203
	return GetStringWithArgs(buffr, string, (int32*)_decode_parameters);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   204
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   205
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   206
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   207
// This function takes a C-string and allocates a temporary string ID.
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   208
// The duration of the bound string is valid only until the next GetString,
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   209
// so be careful.
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   210
StringID BindCString(const char *str)
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   211
{
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   212
	int idx = (++_bind_index) & (NUM_BOUND_STRINGS - 1);
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   213
	_bound_strings[idx] = str;
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   214
	return idx + STR_SPEC_DYNSTRING;
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   215
}
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   216
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   217
// This function is used to "bind" a C string to a OpenTTD dparam slot.
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   218
void SetDParamStr(uint n, const char *str)
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   219
{
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   220
	SetDParam(n, BindCString(str));
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   221
}
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   222
1309
4403a69da4f8 (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
   223
void InjectDParam(int amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   225
	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
static const uint32 _divisor_table[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
	1000000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	100000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	10000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	1000000,
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
	100000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	10000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	1000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	100,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   242
static char *FormatCommaNumber(char *buff, int32 number)
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
	uint32 quot,divisor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	uint32 tot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	uint32 num;
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
	if (number < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
		*buff++ = '-';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	tot = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   257
	for (i = 0; i != 10; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
		divisor = _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		quot = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		if (num >= divisor) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
			quot = num / _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
			num = num % _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   264
		if (tot |= quot || i == 9) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   265
			*buff++ = '0' + quot;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   266
			if (i == 0 || i == 3 || i == 6) *buff++ = ',';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
		}
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
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   270
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   275
static char *FormatNoCommaNumber(char *buff, int32 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	uint32 quot,divisor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	uint32 tot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	uint32 num;
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
	if (number < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		*buff++ = '-';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	tot = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   290
	for (i = 0; i != 10; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
		divisor = _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		quot = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		if (num >= divisor) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
			quot = num / _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
			num = num % _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
		}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   297
		if (tot |= quot || i == 9) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   298
			*buff++ = '0' + quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   302
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   308
static char *FormatYmdString(char *buff, uint16 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
{
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   310
	const char *src;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	YearMonthDay ymd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	ConvertDayToYMD(&ymd, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   315
	for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   316
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	buff[-1] = ' ';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	buff[3] = ' ';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   321
	return FormatNoCommaNumber(buff + 4, ymd.year + MAX_YEAR_BEGIN_REAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   324
static char *FormatMonthAndYear(char *buff, uint16 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
	const char *src;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	YearMonthDay ymd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	ConvertDayToYMD(&ymd, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   331
	for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	buff[-1] = ' ';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
970
24abd02b1092 (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 919
diff changeset
   334
	return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   337
static char *FormatTinyDate(char *buff, uint16 number)
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   338
{
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   339
	YearMonthDay ymd;
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   340
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   341
	ConvertDayToYMD(&ymd, number);
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   342
	buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL);
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   343
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   344
	return buff;
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   345
}
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   346
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   347
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	const char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	char c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	char buf[40], *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	// multiply by exchange rate
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	number *= spec->rate;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	// convert from negative
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   358
	if (number < 0) {
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   359
		*buff++ = '-';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   360
		number = -number;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   361
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   362
788
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   363
	// add prefix part
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   364
	s = spec->prefix;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   365
	while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	// for huge numbers, compact the number into k or M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	if (compact) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		compact = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		if (number >= 1000000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
			number = (number + 500000) / 1000000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
			compact = 'M';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
		} else if (number >= 1000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			number = (number + 500) / 1000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			compact = 'k';
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   376
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   378
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	// convert to ascii number and add commas
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	p = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	j = 4;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   382
	do {
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   383
		if (--j == 0) {
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   384
			*p++ = spec->separator;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   385
			j = 3;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   386
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		*p++ = '0' + number % 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	} while (number /= 10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	do *buff++ = *--p; while (p != buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
	if (compact) *buff++ = compact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
788
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   393
	// add suffix part
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   394
	s = spec->suffix;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   395
	while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   400
static int DeterminePluralForm(int32 n)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   401
{
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   402
	// The absolute value determines plurality
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   403
	if (n < 0) n = -n;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   404
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   405
	switch(_langpack->plural_form) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   406
	// Two forms, singular used for one only
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   407
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   408
	//   Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish,
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   409
	//   Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   410
	case 0:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   411
	default:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   412
		return n != 1;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   413
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   414
	// Only one form
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   415
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   416
	//   Hungarian, Japanese, Korean, Turkish
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   417
	case 1:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   418
		return 0;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   419
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   420
	// Two forms, singular used for zero and one
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   421
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   422
	//   French, Brazilian Portuguese
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   423
	case 2:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   424
		return n > 1;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   425
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   426
	// Three forms, special case for zero
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   427
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   428
	//   Latvian
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   429
	case 3:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   430
		return n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   431
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   432
	// Three forms, special case for one and two
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   433
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   434
	//   Gaelige (Irish)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   435
	case 4:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   436
		return n==1 ? 0 : n==2 ? 1 : 2;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   437
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   438
	// Three forms, special case for numbers ending in 1[2-9]
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   439
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   440
	//   Lithuanian
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   441
	case 5:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   442
		return n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   443
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   444
	// Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   445
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   446
	//   Croatian, Czech, Russian, Slovak, Ukrainian
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   447
	case 6:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   448
		return n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   449
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   450
	// Three forms, special case for one and some numbers ending in 2, 3, or 4
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   451
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   452
	//   Polish
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   453
	case 7:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   454
		return n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   455
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   456
	// Four forms, special case for one and all numbers ending in 02, 03, or 04
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   457
	// Used in:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   458
	//   Slovenian
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   459
	case 8:
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   460
		return n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   461
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   462
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   463
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   464
static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   465
{
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   466
	//<NUM> {Length of each string} {each string}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   467
	uint n = (byte)*b++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   468
	uint pos,i, mylen=0,mypos=0;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   469
	for(i=pos=0; i!=n; i++) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   470
		uint len = (byte)*b++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   471
		if (i == form) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   472
			mypos = pos;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   473
			mylen = len;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   474
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   475
		pos += len;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   476
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   477
	*dstlen = mylen;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   478
	memcpy(dst, b + mypos, mylen);
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   479
	return b + pos;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   480
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   481
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   482
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   483
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	byte b;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   486
	const int32 *argv_orig = argv;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   487
	uint modifier = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   489
	while ((b = *str++) != '\0') {
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   490
		switch (b) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
		case 0x1: // {SETX}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
			*buff++ = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
			*buff++ = *str++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
		case 0x2: // {SETXY}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
			*buff++ = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
			*buff++ = *str++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
			*buff++ = *str++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
			break;
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   500
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
		case 0x81: // {STRINL}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
			str += 2;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   503
			buff = GetStringWithArgs(buff, READ_LE_UINT16(str-2), argv);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
		case 0x82: // {DATE_LONG}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   506
			buff = FormatYmdString(buff, GetInt32(&argv));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
		case 0x83: // {DATE_SHORT}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   509
			buff = FormatMonthAndYear(buff, GetInt32(&argv));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		case 0x84: {// {VELOCITY}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   512
			int value = GetInt32(&argv);
1704
6054160187df (svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents: 1625
diff changeset
   513
			if (_opt_ptr->kilometers) value = value * 1648 >> 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
			buff = FormatCommaNumber(buff, value);
1704
6054160187df (svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents: 1625
diff changeset
   515
			if (_opt_ptr->kilometers) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
				memcpy(buff, " km/h", 5);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
				buff += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
				memcpy(buff, " mph", 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				buff += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   524
		// 0x85 is used as escape character..
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
		case 0x85:
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   526
			switch (*str++) {
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   527
			case 0: /* {CURRCOMPACT} */
2468
9ea52370a093 (svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents: 2410
diff changeset
   528
				buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
				break;
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   530
			case 2: /* {REV} */
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   531
				buff = strecpy(buff, _openttd_revision, NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
				break;
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   533
			case 3: { /* {SHORTCARGO} */
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   534
				// Short description of cargotypes. Layout:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
				// 8-bit = cargo type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
				// 16-bit = cargo count
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   537
				StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][GetInt32(&argv)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
				// liquid type of cargo is multiplied by 100 to get correct amount
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   540
				buff = FormatCommaNumber(buff, GetInt32(&argv) * multiplier);
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   541
				buff = strecpy(buff, " ", NULL);
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   542
				buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   543
			} break;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   544
			case 4: {/* {CURRCOMPACT64} */
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   545
				// 64 bit compact currency-unit
2468
9ea52370a093 (svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents: 2410
diff changeset
   546
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
				break;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   548
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   549
			case 5: { /* {STRING1} */
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   550
				// String that consumes ONE argument
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   551
				uint str = modifier + GetInt32(&argv);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   552
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   553
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   554
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   555
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   556
			case 6: { /* {STRING2} */
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   557
				// String that consumes TWO arguments
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   558
				uint str = modifier + GetInt32(&argv);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   559
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   560
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   561
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   562
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   563
			case 7: { /* {STRING3} */
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   564
				// String that consumes THREE arguments
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   565
				uint str = modifier + GetInt32(&argv);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   566
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   567
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   568
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   569
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   570
			case 8: { /* {STRING4} */
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   571
				// String that consumes FOUR arguments
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   572
				uint str = modifier + GetInt32(&argv);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   573
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   574
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   575
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   576
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   577
			case 9: { /* {STRING5} */
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   578
				// String that consumes FIVE arguments
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   579
				uint str = modifier + GetInt32(&argv);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   580
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   581
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   582
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   583
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   584
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   585
			case 10: { /* {STATIONFEATURES} */
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   586
				buff = StationGetSpecialString(buff, GetInt32(&argv));
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   587
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   588
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   590
			case 11: { /* {INDUSTRY} */
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   591
				Industry *i = GetIndustry(GetInt32(&argv));
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   592
				int32 args[2];
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   593
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   594
				// industry not valid anymore?
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   595
				if (i->xy == 0)
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   596
					break;
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   597
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   598
				// First print the town name and the industry type name
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   599
				// The string STR_INDUSTRY_PATTERN controls the formatting
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   600
				args[0] = i->town->index;
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   601
				args[1] = i->type + STR_4802_COAL_MINE;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   602
				buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   603
				modifier = 0;
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   604
				break;
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   605
			}
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   606
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   607
			case 12: { // {VOLUME}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   608
				buff = FormatCommaNumber(buff, GetInt32(&argv) * 1000);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   609
				buff = strecpy(buff, " ", NULL);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   610
				buff = FormatString(buff, GetStringPtr(STR_LITERS), NULL, modifier >> 24);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   611
				modifier = 0;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   612
				break;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   613
			}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   614
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   615
			case 13: { // {G 0 Der Die Das}
2643
f1fec6d1559a (svn r3185) const
tron
parents: 2639
diff changeset
   616
				const byte* s = (const byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   617
				int len;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   618
				int gender = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   619
				if (s != NULL && s[0] == 0x87) gender = s[1];
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   620
				str = ParseStringChoice(str, gender, buff, &len);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   621
				buff += len;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   622
				break;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   623
			}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   624
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   625
			case 14: { // {DATE_TINY}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   626
				buff = FormatTinyDate(buff, GetInt32(&argv));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   627
				break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   628
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   629
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   630
			case 15: { // {CARGO}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   631
				// Layout now is:
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   632
				//   8bit   - cargo type
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   633
				//   16-bit - cargo count
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   634
				StringID cargo_str = _cargoc.names_long[GetInt32(&argv)];
2131
77bc2b26980d (svn r2641) Fix: [strings] forgot to increase argv pointer twice for {CARGO}
ludde
parents: 2122
diff changeset
   635
				buff = GetStringWithArgs(buff, cargo_str, argv++);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   636
				break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   637
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   638
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
				error("!invalid escape sequence in string");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
		case 0x86: // {SKIP}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   645
			argv++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
			break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   647
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   648
		// This sets up the gender for the string.
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   649
		// We just ignore this one. It's used in {G 0 Der Die Das} to determine the case.
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   650
		case 0x87: // {GENDER 0}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   651
			str++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
			break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   653
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   654
		case 0x88: {// {STRING}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   655
			uint str = modifier + GetInt32(&argv);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   656
			// WARNING. It's prohibited for the included string to consume any arguments.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   657
			// For included strings that consume argument, you should use STRING1, STRING2 etc.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   658
			// To debug stuff you can set argv to NULL and it will tell you
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   659
			buff = GetStringWithArgs(buff, str, argv);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   660
			modifier = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
			break;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   662
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   664
		case 0x8B: // {COMMA}
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   665
			buff = FormatCommaNumber(buff, GetInt32(&argv));
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   666
			break;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   667
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   668
		case 0x8C: // Move argument pointer
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   669
			argv = argv_orig + (byte)*str++;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   670
			break;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   671
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   672
		case 0x8D: { // {P}
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   673
			int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   674
			int len;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   675
			str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len);
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   676
			buff += len;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   677
			break;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   678
		}
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   679
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   680
		case 0x8E: // {NUM}
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   681
			buff = FormatNoCommaNumber(buff, GetInt32(&argv));
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   682
			break;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   683
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   684
		case 0x8F: // {CURRENCY}
2468
9ea52370a093 (svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents: 2410
diff changeset
   685
			buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false);
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   686
			break;
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   687
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   688
		case 0x99: { // {WAYPOINT}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   689
			int32 temp[2];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   690
			Waypoint *wp = GetWaypoint(GetInt32(&argv));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   691
			StringID str;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   692
			if (wp->string != STR_NULL) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   693
				str = wp->string;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   694
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   695
				temp[0] = wp->town_index;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   696
				temp[1] = wp->town_cn + 1;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   697
				str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   698
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   699
			buff = GetStringWithArgs(buff, str, temp);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   700
		} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
		case 0x9A: { // {STATION}
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2548
diff changeset
   703
			const Station* st = GetStation(GetInt32(&argv));
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   704
			int32 temp[2];
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   705
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   706
			if (st->xy == 0) { // station doesn't exist anymore
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   707
				buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL);
64
93656f16d50a (svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents: 26
diff changeset
   708
				break;
93656f16d50a (svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents: 26
diff changeset
   709
			}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   710
			temp[0] = st->town->townnametype;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   711
			temp[1] = st->town->townnameparts;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   712
			buff = GetStringWithArgs(buff, st->string_id, temp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
		case 0x9B: { // {TOWN}
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2548
diff changeset
   716
			const Town* t = GetTown(GetInt32(&argv));
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   717
			int32 temp[1];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   718
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   719
			assert(t->xy != 0);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2548
diff changeset
   720
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   721
			temp[0] = t->townnameparts;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   722
			buff = GetStringWithArgs(buff, t->townnametype, temp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		case 0x9C: { // {CURRENCY64}
2468
9ea52370a093 (svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents: 2410
diff changeset
   727
			buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   731
		case 0x9D: { // {SETCASE}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   732
			// This is a pseudo command, it's outputted when someone does {STRING.ack}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   733
			// The modifier is added to all subsequent GetStringWithArgs that accept the modifier.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   734
			modifier = (byte)*str++ << 24;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   735
			break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   736
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   737
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   738
		case 0x9E: { // {Used to implement case switching}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   739
			// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   740
			// Each LEN is printed using 2 bytes in big endian order.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   741
			uint num = (byte)*str++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   742
			while (num) {
2107
c7eb140bf9bb (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2087
diff changeset
   743
				if ((byte)str[0] == casei) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   744
					// Found the case, adjust str pointer and continue
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   745
					str += 3;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   746
					break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   747
				}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   748
				// Otherwise skip to the next case
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   749
				str += 3 + (str[1] << 8) + str[2];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   750
				num--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
			}
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   752
			break;
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   753
		}
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   754
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
		default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
			*buff++ = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   759
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   764
static char *StationGetSpecialString(char *buff, int x)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
{
2353
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2291
diff changeset
   766
	if (x & 0x01) *buff++ = '\x94';
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2291
diff changeset
   767
	if (x & 0x02) *buff++ = '\x95';
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2291
diff changeset
   768
	if (x & 0x04) *buff++ = '\x96';
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2291
diff changeset
   769
	if (x & 0x08) *buff++ = '\x97';
f431786ac7b3 (svn r2879) Major step twoards ISO-8859-15
tron
parents: 2291
diff changeset
   770
	if (x & 0x10) *buff++ = '\x98';
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   771
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   775
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed)
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   776
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   777
	_town_name_generators[ind](buff, seed);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   779
	while (*buff != '\0') buff++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   783
static const char* const _silly_company_names[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	"Bloggs Brothers",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
	"Tiny Transport Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
	"Express Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	"Comfy-Coach & Co.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	"Crush & Bump Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	"Broken & Late Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
	"Sam Speedy & Son",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	"Supersonic Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	"Mike's Motors",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
	"Lightning International",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	"Pannik & Loozit Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
	"Inter-City Transport",
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   796
	"Getout & Pushit Ltd."
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   799
static const char* const _surname_list[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	"Adams",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
	"Allan",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	"Baker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
	"Bigwig",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	"Black",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
	"Bloggs",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	"Brown",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	"Campbell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	"Gordon",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	"Hamilton",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	"Hawthorn",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
	"Higgins",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
	"Green",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
	"Gribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
	"Jones",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	"McAlpine",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	"MacDonald",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	"McIntosh",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
	"Muir",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
	"Murphy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
	"Nelson",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
	"O'Donnell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	"Parker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	"Phillips",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	"Pilkington",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	"Quigley",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
	"Sharkey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	"Thomson",
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   828
	"Watkins"
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   829
};
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   830
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   831
static const char* const _silly_surname_list[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	"Grumpy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	"Dozy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
	"Speedy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
	"Nosey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	"Dribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
	"Mushroom",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
	"Cabbage",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
	"Sniffle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	"Fishy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
	"Swindle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	"Sneaky",
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   843
	"Nutkins"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   846
static const char _initial_name_letters[] = {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   847
	'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   848
	'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
   849
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   851
static char *GenAndCoName(char *buff, uint32 arg)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
{
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   853
	const char* const* base;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   854
	uint num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
1704
6054160187df (svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents: 1625
diff changeset
   856
	if (_opt_ptr->landscape == LT_CANDY) {
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   857
		base = _silly_surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   858
		num  = lengthof(_silly_surname_list);
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   859
	} else {
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   860
		base = _surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   861
		num  = lengthof(_surname_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   864
	buff = strecpy(buff, base[num * GB(arg, 16, 8) >> 8], NULL);
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   865
	buff = strecpy(buff, " & Co.", NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   870
static char *GenPresidentName(char *buff, uint32 x)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
{
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   872
	const char* const* base;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   873
	uint num;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   874
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   876
	buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	buff[1] = '.';
233
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   878
	buff[2] = ' '; // Insert a space after initial and period "I. Firstname" instead of "I.Firstname"
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   879
	buff += 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   881
	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
   882
	if (i < sizeof(_initial_name_letters)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
		buff[0] = _initial_name_letters[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
		buff[1] = '.';
233
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   885
		buff[2] = ' '; // Insert a space after initial and period "I. J. Firstname" instead of "I.J.Firstname"
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   886
		buff += 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
1704
6054160187df (svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents: 1625
diff changeset
   889
	if (_opt_ptr->landscape == LT_CANDY) {
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   890
		base = _silly_surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   891
		num  = lengthof(_silly_surname_list);
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   892
	} else {
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   893
		base = _surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   894
		num  = lengthof(_surname_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
   897
	buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
static const char * const _song_names[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
	"Tycoon DELUXE Theme",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	"Easy Driver",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	"Little Red Diesel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	"Cruise Control",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	"Don't Walk!",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	"Fell Apart On Me",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	"City Groove",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
	"Funk Central",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	"Stoke It",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	"Road Hog",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
	"Aliens Ate My Railway",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	"Snarl Up",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	"Stroll On",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
	"Can't Get There From Here",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
	"Sawyer's Tune",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	"Hold That Train!",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	"Movin' On",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	"Goss Groove",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	"Small Town",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	"Broomer's Oil Rag",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	"Jammit",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	"Hard Drivin'"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   927
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
{
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   929
	switch (ind) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   930
		case 1: // not used
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   931
			return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   933
		case 2: // used for Foobar & Co company names
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   934
			return GenAndCoName(buff, GetInt32(&argv));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   936
		case 3: // President name
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   937
			return GenPresidentName(buff, GetInt32(&argv));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   939
		case 4: // song names
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   940
			return strecpy(buff, _song_names[GetInt32(&argv) - 1], NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	// town name?
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   944
	if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   945
		buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv));
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   946
		return strecpy(buff, " Transport", NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
	// language name?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   952
		return strecpy(buff,
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   953
			i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	// resolution size?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
		return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	// screenshot format name?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
		int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
   965
		return strecpy(buff, GetScreenshotFormatDesc(i), NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
// remap a string ID from the old format to the new format
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
StringID RemapOldStringID(StringID s)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
{
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   975
	switch (s) {
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   976
		case 0x0006: return STR_SV_EMPTY;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   977
		case 0x7000: return STR_SV_UNNAMED;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   978
		case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   979
		case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   980
		case 0x8864: return STR_SV_TRAIN_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   981
		case 0x902B: return STR_SV_ROADVEH_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   982
		case 0x9830: return STR_SV_SHIP_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   983
		case 0xA02F: return STR_SV_AIRCRAFT_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   984
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   985
		default:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   986
			if (IS_INT_INSIDE(s, 0x300F, 0x3030))
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   987
				return s - 0x300F + STR_SV_STNAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   988
			else
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   989
				return s;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   990
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   993
bool ReadLanguagePack(int lang_index)
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   994
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	int tot_count, i;
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
   996
	LanguagePack *lang_pack;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	size_t len;
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   998
	char **langpack_offs;
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   999
	char *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
		char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
		lang_pack = ReadFileToMem(lang, &len, 100000);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
		free(lang);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	if (lang_pack == NULL) return false;
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1007
	if (len < sizeof(LanguagePack) ||
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1008
			lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1009
			lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		free(lang_pack);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
  1013
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
#if defined(TTD_BIG_ENDIAN)
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1015
	for (i = 0; i != 32; i++) {
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1016
		lang_pack->offsets[i] = READ_LE_UINT16(&lang_pack->offsets[i]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	tot_count = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1021
	for (i = 0; i != 32; i++) {
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1022
		uint num = lang_pack->offsets[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
		_langtab_start[i] = tot_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
		_langtab_num[i] = num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
		tot_count += num;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
	// Allocate offsets
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1029
	langpack_offs = malloc(tot_count * sizeof(*langpack_offs));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
	// Fill offsets
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1032
	s = lang_pack->data;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1033
	for (i = 0; i != tot_count; i++) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1034
		len = (byte)*s;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1035
		*s++ = '\0'; // zero terminate the string before.
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1036
		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
  1037
		langpack_offs[i] = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
		s += len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1041
	free(_langpack);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	_langpack = lang_pack;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1044
	free(_langpack_offs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	_langpack_offs = langpack_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
	_dynlang.curr = lang_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
// make a list of the available language packs. put the data in _dynlang struct.
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 970
diff changeset
  1055
void InitializeLanguagePacks(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	DynamicLanguages *dl = &_dynlang;
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1058
	int i;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1059
	int n;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1060
	int m;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1061
	int def;
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1062
	int fallback;
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1063
	LanguagePack hdr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
	FILE *in;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	char *files[32];
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1066
	uint j;
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1067
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1068
	char lang[] = "en";
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1069
	static const char* env[] = {
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1070
		"LANGUAGE",
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1071
		"LC_ALL",
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1072
		"LC_MESSAGES",
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1073
		"LANG"
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1074
	};
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1075
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1076
	for (j = 0; j < lengthof(env); j++) {
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1077
		const char* envlang = getenv(env[j]);
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1078
		if (envlang != NULL) {
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1079
			snprintf(lang, lengthof(lang), "%.2s", envlang);
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1080
			break;
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1081
		}
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1082
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	n = GetLanguageList(files, lengthof(files));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1086
	def = -1;
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1087
	fallback = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	// go through the language files and make sure that they are valid.
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1090
	for (i = m = 0; i != n; i++) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1091
		int j;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1092
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
		char *s = str_fmt("%s%s", _path.lang_dir, files[i]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
		in = fopen(s, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
		free(s);
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1096
		if (in == NULL ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
				(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
				hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
				hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
			free(files[i]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
			continue;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
		dl->ent[m].file = files[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
		dl->ent[m].name = strdup(hdr.name);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
  1106
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1107
		if (strcmp(hdr.name, "English") == 0) fallback = m;
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1108
		if (strcmp(hdr.isocode, lang) == 0) def = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
		m++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	}
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1112
	if (def == -1) def = fallback;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	if (m == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
		error(n == 0 ? "No available language packs" : "Invalid version of language packs");
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
  1116
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	dl->num = m;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1118
	for (i = 0; i != dl->num; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
		dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	dl->dropdown[i] = INVALID_STRING_ID;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1122
	for (i = 0; i != dl->num; i++)
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1123
		if (strcmp(dl->ent[i].file, dl->curr_file) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
			def = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	if (!ReadLanguagePack(def))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
		error("can't read language pack '%s'", dl->ent[def].file);
2075
21d2986569d1 (svn r2585) - Fix [Makefile]: some small cleanups, remove warnings, and add mersenne to makefile (Luca)
Darkvater
parents: 2070
diff changeset
  1130
}