author | peter1138 |
Fri, 20 Oct 2006 19:48:25 +0000 | |
changeset 4898 | 68560c75ec28 |
parent 4840 | 176bc2a66322 |
child 4912 | d04b3f2bca70 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1853
diff
changeset
|
4 |
#include "openttd.h" |
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2257
diff
changeset
|
5 |
#include "currency.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
1317
f382f1b439c7
(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
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1306
diff
changeset
|
8 |
#include "strings.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
504
diff
changeset
|
9 |
#include "table/strings.h" |
1306
40038dfdf3ba
(svn r1810) Move town name generation declarations into a header of their own
tron
parents:
1102
diff
changeset
|
10 |
#include "namegen.h" |
0 | 11 |
#include "station.h" |
12 |
#include "town.h" |
|
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 | 15 |
#include "screenshot.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1376
diff
changeset
|
16 |
#include "waypoint.h" |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
17 |
#include "industry.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
18 |
#include "variables.h" |
3601
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
19 |
#include "newgrf_text.h" |
3616
7ba7353d6561
(svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents:
3601
diff
changeset
|
20 |
#include "table/landscape_const.h" |
4120
90e678fd7d8d
(svn r5464) [Behaviour Fix] : When starting the game, the system will now verify the presence of music files in gm forlder.
belugas
parents:
3833
diff
changeset
|
21 |
#include "music.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4219
diff
changeset
|
22 |
#include "date.h" |
0 | 23 |
|
4219
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
24 |
#ifdef WIN32 |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
25 |
/* for opendir/readdir/closedir */ |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
26 |
# include "fios.h" |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
27 |
#else |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
28 |
# include <sys/types.h> |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
29 |
# include <dirent.h> |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
30 |
#endif /* WIN32 */ |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
31 |
|
2201 | 32 |
char _userstring[128]; |
33 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
34 |
static char *StationGetSpecialString(char *buff, int x); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
35 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
36 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv); |
0 | 37 |
|
2087 | 38 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei); |
0 | 39 |
|
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
40 |
typedef struct LanguagePack { |
0 | 41 |
uint32 ident; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
42 |
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
43 |
char name[32]; // the international name of this language |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
44 |
char own_name[32]; // the localized name of this language |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
45 |
char isocode[16]; // the ISO code for the language (not country code) |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
46 |
uint16 offsets[32]; // the offsets |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
47 |
byte plural_form; // how to compute plural forms |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
48 |
byte pad[3]; // pad header to be a multiple of 4 |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
49 |
char data[VARARRAY_SIZE]; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
50 |
} LanguagePack; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
51 |
|
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
52 |
static char **_langpack_offs; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
53 |
static LanguagePack *_langpack; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
54 |
static uint _langtab_num[32]; // Offset into langpack offs |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
55 |
static uint _langtab_start[32]; // Offset into langpack offs |
0 | 56 |
|
1321 | 57 |
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = { |
1316 | 58 |
{ /* LT_NORMAL */ |
59 |
STR_PASSENGERS, |
|
60 |
STR_TONS, |
|
61 |
STR_BAGS, |
|
62 |
STR_LITERS, |
|
63 |
STR_ITEMS, |
|
64 |
STR_CRATES, |
|
65 |
STR_TONS, |
|
66 |
STR_TONS, |
|
67 |
STR_TONS, |
|
68 |
STR_TONS, |
|
69 |
STR_BAGS, |
|
70 |
STR_RES_OTHER |
|
71 |
}, |
|
72 |
||
73 |
{ /* LT_HILLY */ |
|
74 |
STR_PASSENGERS, |
|
75 |
STR_TONS, |
|
76 |
STR_BAGS, |
|
77 |
STR_LITERS, |
|
78 |
STR_ITEMS, |
|
79 |
STR_CRATES, |
|
80 |
STR_TONS, |
|
81 |
STR_TONS, |
|
82 |
STR_RES_OTHER, |
|
83 |
STR_TONS, |
|
84 |
STR_BAGS, |
|
85 |
STR_TONS |
|
86 |
}, |
|
87 |
||
88 |
{ /* LT_DESERT */ |
|
89 |
STR_PASSENGERS, |
|
90 |
STR_LITERS, |
|
91 |
STR_BAGS, |
|
92 |
STR_LITERS, |
|
93 |
STR_TONS, |
|
94 |
STR_CRATES, |
|
95 |
STR_TONS, |
|
96 |
STR_TONS, |
|
97 |
STR_TONS, |
|
98 |
STR_LITERS, |
|
99 |
STR_BAGS, |
|
100 |
STR_TONS |
|
101 |
}, |
|
102 |
||
103 |
{ /* LT_CANDY */ |
|
104 |
STR_PASSENGERS, |
|
105 |
STR_TONS, |
|
106 |
STR_BAGS, |
|
107 |
STR_NOTHING, |
|
108 |
STR_NOTHING, |
|
109 |
STR_TONS, |
|
110 |
STR_TONS, |
|
111 |
STR_LITERS, |
|
112 |
STR_TONS, |
|
113 |
STR_NOTHING, |
|
114 |
STR_LITERS, |
|
115 |
STR_NOTHING |
|
116 |
} |
|
0 | 117 |
}; |
118 |
||
119 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
120 |
// Read an int64 from the argv array. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
121 |
static inline int64 GetInt64(const int32 **argv) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
122 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
123 |
int64 result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
124 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
125 |
assert(argv); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
126 |
result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
127 |
(*argv)+=2; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
128 |
return result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
129 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
130 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
131 |
// Read an int32 from the argv array. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
132 |
static inline int32 GetInt32(const int32 **argv) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
133 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
134 |
assert(argv); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
135 |
return *(*argv)++; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
136 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
137 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
138 |
// Read an array from the argv array. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
139 |
static inline const int32 *GetArgvPtr(const int32 **argv, int n) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
140 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
141 |
const int32 *result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
142 |
assert(*argv); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
143 |
result = *argv; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
144 |
(*argv) += n; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
145 |
return result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
146 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
147 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
148 |
|
2055
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
149 |
#define NUM_BOUND_STRINGS 8 |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
150 |
|
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
151 |
// Array to hold the bound strings. |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
152 |
static const char *_bound_strings[NUM_BOUND_STRINGS]; |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
153 |
|
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
154 |
// This index is used to implement a "round-robin" allocating of |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
155 |
// slots for BindCString. NUM_BOUND_STRINGS slots are reserved. |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
156 |
// Which means that after NUM_BOUND_STRINGS calls to BindCString, |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
157 |
// the indices will be reused. |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
158 |
static int _bind_index; |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
159 |
|
1321 | 160 |
static const char *GetStringPtr(StringID string) |
0 | 161 |
{ |
162 |
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; |
|
163 |
} |
|
164 |
||
2087 | 165 |
// The highest 8 bits of string contain the "case index". |
166 |
// These 8 bits will only be set when FormatString wants to print |
|
167 |
// the string in a different case. No one else except FormatString |
|
4405
262b9ef8ab8f
(svn r6158) -Revert r6139 as that breaks strings with cases. Thanks michi_cc
Darkvater
parents:
4386
diff
changeset
|
168 |
// should set those bits, therefore string CANNOT be StringID, but uint32. |
4416
e0e9a72882d0
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4405
diff
changeset
|
169 |
static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv) |
0 | 170 |
{ |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2131
diff
changeset
|
171 |
uint index = GB(string, 0, 11); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2131
diff
changeset
|
172 |
uint tab = GB(string, 11, 5); |
4710
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
173 |
char buff[512]; |
0 | 174 |
|
2635 | 175 |
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString"); |
0 | 176 |
|
1321 | 177 |
switch (tab) { |
178 |
case 4: |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
179 |
if (index >= 0xC0) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
180 |
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv)); |
1321 | 181 |
break; |
182 |
||
183 |
case 14: |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
184 |
if (index >= 0xE4) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
185 |
return GetSpecialPlayerNameString(buffr, index - 0xE4, argv); |
1321 | 186 |
break; |
187 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
188 |
// User defined name |
1321 | 189 |
case 15: |
190 |
return GetName(index, buffr); |
|
191 |
||
4710
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
192 |
case 26: |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
193 |
/* Include string within newgrf text (format code 81) */ |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
194 |
if (HASBIT(index, 10)) { |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
195 |
StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10)); |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
196 |
return GetStringWithArgs(buffr, string, argv); |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
197 |
} |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
198 |
break; |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
199 |
|
3601
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
200 |
case 28: |
4710
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
201 |
GetGRFString(buff, index); |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
202 |
return FormatString(buffr, buff, argv, 0); |
3601
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
203 |
|
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
204 |
case 29: |
4710
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
205 |
GetGRFString(buff, index + 0x800); |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
206 |
return FormatString(buffr, buff, argv, 0); |
3601
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
207 |
|
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
208 |
case 30: |
4710
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
209 |
GetGRFString(buff, index + 0x1000); |
a663b32b9f96
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
210 |
return FormatString(buffr, buff, argv, 0); |
3601
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
211 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
212 |
case 31: |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
213 |
// dynamic strings. These are NOT to be passed through the formatter, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
214 |
// but passed through verbatim. |
2055
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
215 |
if (index < (STR_SPEC_USERSTRING & 0x7FF)) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
216 |
return strecpy(buffr, _bound_strings[index], NULL); |
2055
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
217 |
} |
1321 | 218 |
|
2087 | 219 |
return FormatString(buffr, _userstring, NULL, 0); |
0 | 220 |
} |
221 |
||
2639 | 222 |
if (index >= _langtab_num[tab]) { |
1321 | 223 |
error( |
224 |
"!String 0x%X is invalid. " |
|
225 |
"Probably because an old version of the .lng file.\n", string |
|
226 |
); |
|
2639 | 227 |
} |
0 | 228 |
|
2635 | 229 |
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8)); |
0 | 230 |
} |
231 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
232 |
char *GetString(char *buffr, StringID string) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
233 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
234 |
return GetStringWithArgs(buffr, string, (int32*)_decode_parameters); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
235 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
236 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
237 |
|
2055
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
238 |
// This function takes a C-string and allocates a temporary string ID. |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
239 |
// The duration of the bound string is valid only until the next GetString, |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
240 |
// so be careful. |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
241 |
StringID BindCString(const char *str) |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
242 |
{ |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
243 |
int idx = (++_bind_index) & (NUM_BOUND_STRINGS - 1); |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
244 |
_bound_strings[idx] = str; |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
245 |
return idx + STR_SPEC_DYNSTRING; |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
246 |
} |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
247 |
|
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
248 |
// This function is used to "bind" a C string to a OpenTTD dparam slot. |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
249 |
void SetDParamStr(uint n, const char *str) |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
250 |
{ |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
251 |
SetDParam(n, BindCString(str)); |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
252 |
} |
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2053
diff
changeset
|
253 |
|
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1306
diff
changeset
|
254 |
void InjectDParam(int amount) |
0 | 255 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
256 |
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); |
0 | 257 |
} |
258 |
||
259 |
static const uint32 _divisor_table[] = { |
|
260 |
1000000000, |
|
261 |
100000000, |
|
262 |
10000000, |
|
263 |
1000000, |
|
264 |
||
265 |
100000, |
|
266 |
10000, |
|
267 |
1000, |
|
268 |
100, |
|
269 |
10, |
|
270 |
1 |
|
271 |
}; |
|
272 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
273 |
static char *FormatCommaNumber(char *buff, int32 number) |
0 | 274 |
{ |
275 |
uint32 quot,divisor; |
|
276 |
int i; |
|
277 |
uint32 tot; |
|
278 |
uint32 num; |
|
279 |
||
280 |
if (number < 0) { |
|
281 |
*buff++ = '-'; |
|
282 |
number = -number; |
|
283 |
} |
|
284 |
||
285 |
num = number; |
|
286 |
||
287 |
tot = 0; |
|
1316 | 288 |
for (i = 0; i != 10; i++) { |
0 | 289 |
divisor = _divisor_table[i]; |
290 |
quot = 0; |
|
291 |
if (num >= divisor) { |
|
292 |
quot = num / _divisor_table[i]; |
|
293 |
num = num % _divisor_table[i]; |
|
294 |
} |
|
1316 | 295 |
if (tot |= quot || i == 9) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
296 |
*buff++ = '0' + quot; |
1316 | 297 |
if (i == 0 || i == 3 || i == 6) *buff++ = ','; |
0 | 298 |
} |
299 |
} |
|
300 |
||
1316 | 301 |
*buff = '\0'; |
0 | 302 |
|
303 |
return buff; |
|
304 |
} |
|
305 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
306 |
static char *FormatNoCommaNumber(char *buff, int32 number) |
0 | 307 |
{ |
308 |
uint32 quot,divisor; |
|
309 |
int i; |
|
310 |
uint32 tot; |
|
311 |
uint32 num; |
|
312 |
||
313 |
if (number < 0) { |
|
314 |
*buff++ = '-'; |
|
315 |
number = -number; |
|
316 |
} |
|
317 |
||
318 |
num = number; |
|
319 |
||
320 |
tot = 0; |
|
1316 | 321 |
for (i = 0; i != 10; i++) { |
0 | 322 |
divisor = _divisor_table[i]; |
323 |
quot = 0; |
|
324 |
if (num >= divisor) { |
|
325 |
quot = num / _divisor_table[i]; |
|
326 |
num = num % _divisor_table[i]; |
|
327 |
} |
|
1316 | 328 |
if (tot |= quot || i == 9) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
329 |
*buff++ = '0' + quot; |
0 | 330 |
} |
331 |
} |
|
332 |
||
1316 | 333 |
*buff = '\0'; |
0 | 334 |
|
335 |
return buff; |
|
336 |
} |
|
337 |
||
338 |
||
4289
ff1b2b915cab
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
339 |
static char *FormatYmdString(char *buff, Date date) |
0 | 340 |
{ |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
341 |
const char *src; |
0 | 342 |
YearMonthDay ymd; |
343 |
||
4289
ff1b2b915cab
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
344 |
ConvertDateToYMD(date, &ymd); |
0 | 345 |
|
1316 | 346 |
for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {} |
0 | 347 |
buff[-1] = ' '; |
3832
dfc3bcc5c679
(svn r4854) - Codechange: don't assume a short format month is 3 characters -- copy the string in the same way the other parts
peter1138
parents:
3616
diff
changeset
|
348 |
|
dfc3bcc5c679
(svn r4854) - Codechange: don't assume a short format month is 3 characters -- copy the string in the same way the other parts
peter1138
parents:
3616
diff
changeset
|
349 |
for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
dfc3bcc5c679
(svn r4854) - Codechange: don't assume a short format month is 3 characters -- copy the string in the same way the other parts
peter1138
parents:
3616
diff
changeset
|
350 |
buff[-1] = ' '; |
0 | 351 |
|
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4289
diff
changeset
|
352 |
return FormatNoCommaNumber(buff, ymd.year); |
0 | 353 |
} |
354 |
||
4289
ff1b2b915cab
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
355 |
static char *FormatMonthAndYear(char *buff, Date date) |
0 | 356 |
{ |
357 |
const char *src; |
|
358 |
YearMonthDay ymd; |
|
359 |
||
4289
ff1b2b915cab
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
360 |
ConvertDateToYMD(date, &ymd); |
0 | 361 |
|
1316 | 362 |
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
0 | 363 |
buff[-1] = ' '; |
364 |
||
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4289
diff
changeset
|
365 |
return FormatNoCommaNumber(buff, ymd.year); |
0 | 366 |
} |
367 |
||
4289
ff1b2b915cab
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
368 |
static char *FormatTinyDate(char *buff, Date date) |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
369 |
{ |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
370 |
YearMonthDay ymd; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
371 |
|
4289
ff1b2b915cab
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
372 |
ConvertDateToYMD(date, &ymd); |
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4289
diff
changeset
|
373 |
buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year); |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
374 |
|
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
375 |
return buff; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
376 |
} |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
377 |
|
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
378 |
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact) |
0 | 379 |
{ |
380 |
const char *s; |
|
381 |
char c; |
|
382 |
char buf[40], *p; |
|
383 |
int j; |
|
384 |
||
385 |
// multiply by exchange rate |
|
386 |
number *= spec->rate; |
|
387 |
||
388 |
// convert from negative |
|
1316 | 389 |
if (number < 0) { |
390 |
*buff++ = '-'; |
|
391 |
number = -number; |
|
392 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
393 |
|
4602
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
394 |
/* Add prefix part, folowing symbol_pos specification. |
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
395 |
* Here, it can can be either 0 (prefix) or 2 (both prefix anf suffix). |
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
396 |
* The only remaining value is 1 (suffix), so everything that is not 1 */ |
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
397 |
if (spec->symbol_pos != 1){ |
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
398 |
s = spec->prefix; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
399 |
while (s != spec->prefix + lengthof(spec->prefix) && (c = *(s++)) != '\0') *(buff)++ = c; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
400 |
} |
0 | 401 |
|
402 |
// for huge numbers, compact the number into k or M |
|
403 |
if (compact) { |
|
404 |
compact = 0; |
|
405 |
if (number >= 1000000000) { |
|
406 |
number = (number + 500000) / 1000000; |
|
407 |
compact = 'M'; |
|
408 |
} else if (number >= 1000000) { |
|
409 |
number = (number + 500) / 1000; |
|
410 |
compact = 'k'; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
411 |
} |
0 | 412 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
413 |
|
0 | 414 |
// convert to ascii number and add commas |
415 |
p = buf; |
|
416 |
j = 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
417 |
do { |
1316 | 418 |
if (--j == 0) { |
419 |
*p++ = spec->separator; |
|
420 |
j = 3; |
|
421 |
} |
|
0 | 422 |
*p++ = '0' + number % 10; |
423 |
} while (number /= 10); |
|
424 |
do *buff++ = *--p; while (p != buf); |
|
425 |
||
426 |
if (compact) *buff++ = compact; |
|
427 |
||
4602
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
428 |
/* Add suffix part, folowing symbol_pos specification. |
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
429 |
* Here, it can can be either 1 (suffix) or 2 (both prefix anf suffix). |
36e779efee9a
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
430 |
* The only remaining value is 1 (prefix), so everything that is not 0 */ |
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
431 |
if (spec->symbol_pos != 0) { |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
432 |
s = spec->suffix; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
433 |
while (s != spec->suffix + lengthof(spec->suffix) && (c = *(s++)) != '\0') *(buff++) = c; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
434 |
} |
0 | 435 |
|
436 |
return buff; |
|
437 |
} |
|
438 |
||
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
439 |
static int DeterminePluralForm(int32 n) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
440 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
441 |
// The absolute value determines plurality |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
442 |
if (n < 0) n = -n; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
443 |
|
2952 | 444 |
switch (_langpack->plural_form) { |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
445 |
// Two forms, singular used for one only |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
446 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
447 |
// Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
448 |
// Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
449 |
case 0: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
450 |
default: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
451 |
return n != 1; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
452 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
453 |
// Only one form |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
454 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
455 |
// Hungarian, Japanese, Korean, Turkish |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
456 |
case 1: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
457 |
return 0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
458 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
459 |
// Two forms, singular used for zero and one |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
460 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
461 |
// French, Brazilian Portuguese |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
462 |
case 2: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
463 |
return n > 1; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
464 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
465 |
// Three forms, special case for zero |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
466 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
467 |
// Latvian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
468 |
case 3: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
469 |
return n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
470 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
471 |
// Three forms, special case for one and two |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
472 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
473 |
// Gaelige (Irish) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
474 |
case 4: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
475 |
return n==1 ? 0 : n==2 ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
476 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
477 |
// Three forms, special case for numbers ending in 1[2-9] |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
478 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
479 |
// Lithuanian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
480 |
case 5: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
481 |
return n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
482 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
483 |
// Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4] |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
484 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
485 |
// Croatian, Czech, Russian, Slovak, Ukrainian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
486 |
case 6: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
487 |
return n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
488 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
489 |
// Three forms, special case for one and some numbers ending in 2, 3, or 4 |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
490 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
491 |
// Polish |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
492 |
case 7: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
493 |
return n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
494 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
495 |
// Four forms, special case for one and all numbers ending in 02, 03, or 04 |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
496 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
497 |
// Slovenian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
498 |
case 8: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
499 |
return n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
500 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
501 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
502 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
503 |
static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
504 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
505 |
//<NUM> {Length of each string} {each string} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
506 |
uint n = (byte)*b++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
507 |
uint pos,i, mylen=0,mypos=0; |
2952 | 508 |
|
509 |
for (i = pos = 0; i != n; i++) { |
|
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
510 |
uint len = (byte)*b++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
511 |
if (i == form) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
512 |
mypos = pos; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
513 |
mylen = len; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
514 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
515 |
pos += len; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
516 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
517 |
*dstlen = mylen; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
518 |
memcpy(dst, b + mypos, mylen); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
519 |
return b + pos; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
520 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
521 |
|
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
522 |
typedef struct Units { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
523 |
int s_m; ///< Multiplier for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
524 |
int s_s; ///< Shift for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
525 |
StringID velocity; ///< String for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
526 |
int p_m; ///< Multiplier for power |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
527 |
int p_s; ///< Shift for power |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
528 |
StringID power; ///< String for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
529 |
int w_m; ///< Multiplier for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
530 |
int w_s; ///< Shift for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
531 |
StringID s_weight; ///< Short string for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
532 |
StringID l_weight; ///< Long string for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
533 |
int v_m; ///< Multiplier for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
534 |
int v_s; ///< Shift for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
535 |
StringID s_volume; ///< Short string for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
536 |
StringID l_volume; ///< Long string for volume |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
537 |
int f_m; ///< Multiplier for force |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
538 |
int f_s; ///< Shift for force |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
539 |
StringID force; ///< String for force |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
540 |
} Units; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
541 |
|
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
542 |
/* Unit conversions */ |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
543 |
static const Units units[] = { |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
544 |
{ // Imperial (Original, mph, hp, metric ton, litre, metric ton force) |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
545 |
10, 4, STR_UNITS_VELOCITY_IMPERIAL, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
546 |
1, 0, STR_UNITS_POWER_IMPERIAL, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
547 |
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
548 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
549 |
835, 13, STR_UNITS_FORCE_METRIC, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
550 |
}, |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
551 |
{ // Metric (km/h, hp, metric ton, litre, metric ton force) |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
552 |
1, 0, STR_UNITS_VELOCITY_METRIC, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
553 |
1, 0, STR_UNITS_POWER_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
554 |
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
555 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
556 |
835, 13, STR_UNITS_FORCE_METRIC, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
557 |
}, |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
558 |
{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton) |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
559 |
284, 10, STR_UNITS_VELOCITY_SI, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
560 |
764, 10, STR_UNITS_POWER_SI, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
561 |
1000, 0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, |
3485
a67571100234
(svn r4336) Fix units conversion of volume for SI
peter1138
parents:
3477
diff
changeset
|
562 |
1, 0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, |
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
563 |
1, 0, STR_UNITS_FORCE_SI, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
564 |
}, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
565 |
}; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
566 |
|
2087 | 567 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei) |
0 | 568 |
{ |
4840
176bc2a66322
(svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents:
4710
diff
changeset
|
569 |
extern const char _openttd_revision[]; |
0 | 570 |
byte b; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
571 |
const int32 *argv_orig = argv; |
2087 | 572 |
uint modifier = 0; |
0 | 573 |
|
1316 | 574 |
while ((b = *str++) != '\0') { |
575 |
switch (b) { |
|
0 | 576 |
case 0x1: // {SETX} |
577 |
*buff++ = b; |
|
578 |
*buff++ = *str++; |
|
579 |
break; |
|
580 |
case 0x2: // {SETXY} |
|
581 |
*buff++ = b; |
|
582 |
*buff++ = *str++; |
|
583 |
*buff++ = *str++; |
|
584 |
break; |
|
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
585 |
|
0 | 586 |
case 0x81: // {STRINL} |
2966
7f382cfeb93d
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2957
diff
changeset
|
587 |
buff = GetStringWithArgs(buff, ReadLE16Unaligned(str), argv); |
0 | 588 |
str += 2; |
589 |
break; |
|
590 |
case 0x82: // {DATE_LONG} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
591 |
buff = FormatYmdString(buff, GetInt32(&argv)); |
0 | 592 |
break; |
593 |
case 0x83: // {DATE_SHORT} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
594 |
buff = FormatMonthAndYear(buff, GetInt32(&argv)); |
0 | 595 |
break; |
596 |
case 0x84: {// {VELOCITY} |
|
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
597 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
598 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
599 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
600 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
601 |
modifier = 0; |
0 | 602 |
break; |
603 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
604 |
// 0x85 is used as escape character.. |
0 | 605 |
case 0x85: |
1316 | 606 |
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
|
607 |
case 0: /* {CURRCOMPACT} */ |
2468
15753a8438ba
(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
|
608 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true); |
0 | 609 |
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
|
610 |
case 2: /* {REV} */ |
1853
2c2f5699e75f
(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents:
1704
diff
changeset
|
611 |
buff = strecpy(buff, _openttd_revision, NULL); |
0 | 612 |
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
|
613 |
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
|
614 |
// Short description of cargotypes. Layout: |
0 | 615 |
// 8-bit = cargo type |
616 |
// 16-bit = cargo count |
|
3616
7ba7353d6561
(svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents:
3601
diff
changeset
|
617 |
StringID cargo_str = _cargo_types_base_values[_opt_ptr->landscape].units_volume[GetInt32(&argv)]; |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
618 |
switch (cargo_str) { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
619 |
case STR_TONS: { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
620 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
621 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
622 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
623 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
624 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
625 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
626 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
627 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
628 |
case STR_LITERS: { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
629 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
630 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
631 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
632 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
633 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
634 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
635 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
636 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
637 |
default: |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
638 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
639 |
buff = strecpy(buff, " ", NULL); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
640 |
buff = strecpy(buff, GetStringPtr(cargo_str), NULL); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
641 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
642 |
} |
1316 | 643 |
} break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
644 |
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
|
645 |
// 64 bit compact currency-unit |
2468
15753a8438ba
(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
|
646 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true); |
0 | 647 |
break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
648 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
649 |
case 5: { /* {STRING1} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
650 |
// String that consumes ONE argument |
2087 | 651 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
652 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1)); |
2087 | 653 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
654 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
655 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
656 |
case 6: { /* {STRING2} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
657 |
// String that consumes TWO arguments |
2087 | 658 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(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, GetArgvPtr(&argv, 2)); |
2087 | 660 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
661 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
662 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
663 |
case 7: { /* {STRING3} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
664 |
// String that consumes THREE arguments |
2087 | 665 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
666 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3)); |
2087 | 667 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
668 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
669 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
670 |
case 8: { /* {STRING4} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
671 |
// String that consumes FOUR arguments |
2087 | 672 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
673 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4)); |
2087 | 674 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
675 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
676 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
677 |
case 9: { /* {STRING5} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
678 |
// String that consumes FIVE arguments |
2087 | 679 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
680 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5)); |
2087 | 681 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
682 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
683 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
684 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
685 |
case 10: { /* {STATIONFEATURES} */ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
686 |
buff = StationGetSpecialString(buff, GetInt32(&argv)); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
687 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
688 |
} |
0 | 689 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
690 |
case 11: { /* {INDUSTRY} */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
691 |
const Industry* i = GetIndustry(GetInt32(&argv)); |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
692 |
int32 args[2]; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
693 |
|
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
694 |
// industry not valid anymore? |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4321
diff
changeset
|
695 |
if (!IsValidIndustry(i)) break; |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
696 |
|
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
697 |
// First print the town name and the industry type name |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
698 |
// The string STR_INDUSTRY_PATTERN controls the formatting |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
699 |
args[0] = i->town->index; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
700 |
args[1] = i->type + STR_4802_COAL_MINE; |
2087 | 701 |
buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24); |
702 |
modifier = 0; |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
703 |
break; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
704 |
} |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
705 |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
706 |
case 12: { // {VOLUME} |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
707 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
708 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
709 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
710 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24); |
2087 | 711 |
modifier = 0; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
712 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
713 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
714 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
715 |
case 13: { // {G 0 Der Die Das} |
2643 | 716 |
const byte* s = (const byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
717 |
int len; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
718 |
int gender = 0; |
2639 | 719 |
if (s != NULL && s[0] == 0x87) gender = s[1]; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
720 |
str = ParseStringChoice(str, gender, buff, &len); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
721 |
buff += len; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
722 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
723 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
724 |
|
2087 | 725 |
case 14: { // {DATE_TINY} |
726 |
buff = FormatTinyDate(buff, GetInt32(&argv)); |
|
727 |
break; |
|
728 |
} |
|
729 |
||
730 |
case 15: { // {CARGO} |
|
731 |
// Layout now is: |
|
732 |
// 8bit - cargo type |
|
733 |
// 16-bit - cargo count |
|
4898
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4840
diff
changeset
|
734 |
CargoID cargo = GetInt32(&argv); |
68560c75ec28
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4840
diff
changeset
|
735 |
StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : _cargoc.names_long[cargo]; |
2131
525edb393b81
(svn r2641) Fix: [strings] forgot to increase argv pointer twice for {CARGO}
ludde
parents:
2122
diff
changeset
|
736 |
buff = GetStringWithArgs(buff, cargo_str, argv++); |
2087 | 737 |
break; |
738 |
} |
|
739 |
||
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
740 |
case 16: { // {POWER} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
741 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
742 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
743 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
744 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
745 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
746 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
747 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
748 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
749 |
case 17: { // {VOLUME_S} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
750 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
751 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
752 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
753 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
754 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
755 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
756 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
757 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
758 |
case 18: { // {WEIGHT} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
759 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
760 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
761 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
762 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
763 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
764 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
765 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
766 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
767 |
case 19: { // {WEIGHT_S} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
768 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
769 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
770 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
771 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
772 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
773 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
774 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
775 |
|
3489
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
776 |
case 20: { // {FORCE} |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
777 |
int32 args[1]; |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
778 |
assert(_opt_ptr->units < lengthof(units)); |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
779 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s; |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
780 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24); |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
781 |
modifier = 0; |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
782 |
break; |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
783 |
} |
1a4ffb2bc0f4
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
784 |
|
0 | 785 |
default: |
786 |
error("!invalid escape sequence in string"); |
|
787 |
} |
|
788 |
break; |
|
789 |
||
790 |
case 0x86: // {SKIP} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
791 |
argv++; |
0 | 792 |
break; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
793 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
794 |
// This sets up the gender for the string. |
2087 | 795 |
// We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
796 |
case 0x87: // {GENDER 0} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
797 |
str++; |
0 | 798 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
799 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
800 |
case 0x88: {// {STRING} |
2087 | 801 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
802 |
// WARNING. It's prohibited for the included string to consume any arguments. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
803 |
// For included strings that consume argument, you should use STRING1, STRING2 etc. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
804 |
// To debug stuff you can set argv to NULL and it will tell you |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
805 |
buff = GetStringWithArgs(buff, str, argv); |
2087 | 806 |
modifier = 0; |
0 | 807 |
break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
808 |
} |
0 | 809 |
|
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
810 |
case 0x8B: // {COMMA} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
811 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
812 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
813 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
814 |
case 0x8C: // Move argument pointer |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
815 |
argv = argv_orig + (byte)*str++; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
816 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
817 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
818 |
case 0x8D: { // {P} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
819 |
int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
820 |
int len; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
821 |
str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len); |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
822 |
buff += len; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
823 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
824 |
} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
825 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
826 |
case 0x8E: // {NUM} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
827 |
buff = FormatNoCommaNumber(buff, GetInt32(&argv)); |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
828 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
829 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
830 |
case 0x8F: // {CURRENCY} |
2468
15753a8438ba
(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
|
831 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false); |
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
832 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
833 |
|
2087 | 834 |
case 0x99: { // {WAYPOINT} |
835 |
int32 temp[2]; |
|
836 |
Waypoint *wp = GetWaypoint(GetInt32(&argv)); |
|
837 |
StringID str; |
|
838 |
if (wp->string != STR_NULL) { |
|
839 |
str = wp->string; |
|
840 |
} else { |
|
841 |
temp[0] = wp->town_index; |
|
842 |
temp[1] = wp->town_cn + 1; |
|
843 |
str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; |
|
844 |
} |
|
845 |
buff = GetStringWithArgs(buff, str, temp); |
|
846 |
} break; |
|
0 | 847 |
|
848 |
case 0x9A: { // {STATION} |
|
2630 | 849 |
const Station* st = GetStation(GetInt32(&argv)); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
850 |
int32 temp[2]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
851 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4321
diff
changeset
|
852 |
if (!IsValidStation(st)) { // station doesn't exist anymore |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
853 |
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
|
854 |
break; |
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
855 |
} |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
856 |
temp[0] = st->town->townnametype; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
857 |
temp[1] = st->town->townnameparts; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
858 |
buff = GetStringWithArgs(buff, st->string_id, temp); |
0 | 859 |
break; |
860 |
} |
|
861 |
case 0x9B: { // {TOWN} |
|
2630 | 862 |
const Town* t = GetTown(GetInt32(&argv)); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
863 |
int32 temp[1]; |
2639 | 864 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4321
diff
changeset
|
865 |
assert(IsValidTown(t)); |
2630 | 866 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
867 |
temp[0] = t->townnameparts; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
868 |
buff = GetStringWithArgs(buff, t->townnametype, temp); |
0 | 869 |
break; |
870 |
} |
|
871 |
||
872 |
case 0x9C: { // {CURRENCY64} |
|
2468
15753a8438ba
(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
|
873 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false); |
0 | 874 |
break; |
875 |
} |
|
876 |
||
2087 | 877 |
case 0x9D: { // {SETCASE} |
2639 | 878 |
// This is a pseudo command, it's outputted when someone does {STRING.ack} |
2087 | 879 |
// The modifier is added to all subsequent GetStringWithArgs that accept the modifier. |
880 |
modifier = (byte)*str++ << 24; |
|
881 |
break; |
|
882 |
} |
|
883 |
||
884 |
case 0x9E: { // {Used to implement case switching} |
|
885 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
|
886 |
// Each LEN is printed using 2 bytes in big endian order. |
|
887 |
uint num = (byte)*str++; |
|
888 |
while (num) { |
|
2107
607a900aefa3
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2087
diff
changeset
|
889 |
if ((byte)str[0] == casei) { |
2087 | 890 |
// Found the case, adjust str pointer and continue |
891 |
str += 3; |
|
892 |
break; |
|
893 |
} |
|
894 |
// Otherwise skip to the next case |
|
895 |
str += 3 + (str[1] << 8) + str[2]; |
|
896 |
num--; |
|
0 | 897 |
} |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
898 |
break; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
899 |
} |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
900 |
|
0 | 901 |
default: |
902 |
*buff++ = b; |
|
903 |
} |
|
904 |
} |
|
1316 | 905 |
*buff = '\0'; |
0 | 906 |
return buff; |
907 |
} |
|
908 |
||
909 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
910 |
static char *StationGetSpecialString(char *buff, int x) |
0 | 911 |
{ |
2353 | 912 |
if (x & 0x01) *buff++ = '\x94'; |
913 |
if (x & 0x02) *buff++ = '\x95'; |
|
914 |
if (x & 0x04) *buff++ = '\x96'; |
|
915 |
if (x & 0x08) *buff++ = '\x97'; |
|
916 |
if (x & 0x10) *buff++ = '\x98'; |
|
1316 | 917 |
*buff = '\0'; |
0 | 918 |
return buff; |
919 |
} |
|
920 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
921 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed) |
1316 | 922 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
923 |
_town_name_generators[ind](buff, seed); |
0 | 924 |
|
1316 | 925 |
while (*buff != '\0') buff++; |
0 | 926 |
return buff; |
927 |
} |
|
928 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
929 |
static const char* const _silly_company_names[] = { |
0 | 930 |
"Bloggs Brothers", |
931 |
"Tiny Transport Ltd.", |
|
932 |
"Express Travel", |
|
933 |
"Comfy-Coach & Co.", |
|
934 |
"Crush & Bump Ltd.", |
|
935 |
"Broken & Late Ltd.", |
|
936 |
"Sam Speedy & Son", |
|
937 |
"Supersonic Travel", |
|
938 |
"Mike's Motors", |
|
939 |
"Lightning International", |
|
940 |
"Pannik & Loozit Ltd.", |
|
941 |
"Inter-City Transport", |
|
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
942 |
"Getout & Pushit Ltd." |
0 | 943 |
}; |
944 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
945 |
static const char* const _surname_list[] = { |
0 | 946 |
"Adams", |
947 |
"Allan", |
|
948 |
"Baker", |
|
949 |
"Bigwig", |
|
950 |
"Black", |
|
951 |
"Bloggs", |
|
952 |
"Brown", |
|
953 |
"Campbell", |
|
954 |
"Gordon", |
|
955 |
"Hamilton", |
|
956 |
"Hawthorn", |
|
957 |
"Higgins", |
|
958 |
"Green", |
|
959 |
"Gribble", |
|
960 |
"Jones", |
|
961 |
"McAlpine", |
|
962 |
"MacDonald", |
|
963 |
"McIntosh", |
|
964 |
"Muir", |
|
965 |
"Murphy", |
|
966 |
"Nelson", |
|
967 |
"O'Donnell", |
|
968 |
"Parker", |
|
969 |
"Phillips", |
|
970 |
"Pilkington", |
|
971 |
"Quigley", |
|
972 |
"Sharkey", |
|
973 |
"Thomson", |
|
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
974 |
"Watkins" |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
975 |
}; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
976 |
|
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
977 |
static const char* const _silly_surname_list[] = { |
0 | 978 |
"Grumpy", |
979 |
"Dozy", |
|
980 |
"Speedy", |
|
981 |
"Nosey", |
|
982 |
"Dribble", |
|
983 |
"Mushroom", |
|
984 |
"Cabbage", |
|
985 |
"Sniffle", |
|
986 |
"Fishy", |
|
987 |
"Swindle", |
|
988 |
"Sneaky", |
|
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
989 |
"Nutkins" |
0 | 990 |
}; |
991 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
992 |
static const char _initial_name_letters[] = { |
1321 | 993 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', |
994 |
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', |
|
0 | 995 |
}; |
996 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
997 |
static char *GenAndCoName(char *buff, uint32 arg) |
0 | 998 |
{ |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
999 |
const char* const* base; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1000 |
uint num; |
0 | 1001 |
|
1704
2525507adda7
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
1002 |
if (_opt_ptr->landscape == LT_CANDY) { |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1003 |
base = _silly_surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1004 |
num = lengthof(_silly_surname_list); |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1005 |
} else { |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1006 |
base = _surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1007 |
num = lengthof(_surname_list); |
0 | 1008 |
} |
1009 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1010 |
buff = strecpy(buff, base[num * GB(arg, 16, 8) >> 8], NULL); |
1853
2c2f5699e75f
(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents:
1704
diff
changeset
|
1011 |
buff = strecpy(buff, " & Co.", NULL); |
0 | 1012 |
|
1013 |
return buff; |
|
1014 |
} |
|
1015 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1016 |
static char *GenPresidentName(char *buff, uint32 x) |
0 | 1017 |
{ |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1018 |
const char* const* base; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1019 |
uint num; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1020 |
uint i; |
0 | 1021 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1022 |
buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8]; |
0 | 1023 |
buff[1] = '.'; |
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
1024 |
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
|
1025 |
buff += 3; |
0 | 1026 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1027 |
i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8; |
0 | 1028 |
if (i < sizeof(_initial_name_letters)) { |
1029 |
buff[0] = _initial_name_letters[i]; |
|
1030 |
buff[1] = '.'; |
|
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
1031 |
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
|
1032 |
buff += 3; |
0 | 1033 |
} |
1034 |
||
1704
2525507adda7
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
1035 |
if (_opt_ptr->landscape == LT_CANDY) { |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1036 |
base = _silly_surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1037 |
num = lengthof(_silly_surname_list); |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1038 |
} else { |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1039 |
base = _surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1040 |
num = lengthof(_surname_list); |
0 | 1041 |
} |
1042 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1043 |
buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], NULL); |
0 | 1044 |
|
1045 |
return buff; |
|
1046 |
} |
|
1047 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1048 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) |
0 | 1049 |
{ |
1316 | 1050 |
switch (ind) { |
1321 | 1051 |
case 1: // not used |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1052 |
return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], NULL); |
0 | 1053 |
|
1321 | 1054 |
case 2: // used for Foobar & Co company names |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1055 |
return GenAndCoName(buff, GetInt32(&argv)); |
0 | 1056 |
|
1321 | 1057 |
case 3: // President name |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1058 |
return GenPresidentName(buff, GetInt32(&argv)); |
0 | 1059 |
|
1321 | 1060 |
case 4: // song names |
4120
90e678fd7d8d
(svn r5464) [Behaviour Fix] : When starting the game, the system will now verify the presence of music files in gm forlder.
belugas
parents:
3833
diff
changeset
|
1061 |
return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, NULL); |
0 | 1062 |
} |
1063 |
||
1064 |
// town name? |
|
1316 | 1065 |
if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1066 |
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv)); |
1853
2c2f5699e75f
(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents:
1704
diff
changeset
|
1067 |
return strecpy(buff, " Transport", NULL); |
0 | 1068 |
} |
1069 |
||
1070 |
// language name? |
|
1071 |
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
|
1072 |
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4); |
|
1853
2c2f5699e75f
(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents:
1704
diff
changeset
|
1073 |
return strecpy(buff, |
2c2f5699e75f
(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents:
1704
diff
changeset
|
1074 |
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL); |
0 | 1075 |
} |
1076 |
||
1077 |
// resolution size? |
|
1078 |
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
|
1079 |
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
|
1080 |
return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]); |
|
1081 |
} |
|
1082 |
||
1083 |
// screenshot format name? |
|
1084 |
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { |
|
1085 |
int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4); |
|
1853
2c2f5699e75f
(svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents:
1704
diff
changeset
|
1086 |
return strecpy(buff, GetScreenshotFormatDesc(i), NULL); |
0 | 1087 |
} |
1088 |
||
1089 |
assert(0); |
|
1090 |
return NULL; |
|
1091 |
} |
|
1092 |
||
1093 |
// remap a string ID from the old format to the new format |
|
1094 |
StringID RemapOldStringID(StringID s) |
|
1095 |
{ |
|
1321 | 1096 |
switch (s) { |
1097 |
case 0x0006: return STR_SV_EMPTY; |
|
1098 |
case 0x7000: return STR_SV_UNNAMED; |
|
1099 |
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1100 |
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1101 |
case 0x8864: return STR_SV_TRAIN_NAME; |
|
1102 |
case 0x902B: return STR_SV_ROADVEH_NAME; |
|
1103 |
case 0x9830: return STR_SV_SHIP_NAME; |
|
1104 |
case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
1105 |
||
1106 |
default: |
|
2951 | 1107 |
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) { |
1321 | 1108 |
return s - 0x300F + STR_SV_STNAME; |
2951 | 1109 |
} else { |
1321 | 1110 |
return s; |
2951 | 1111 |
} |
1321 | 1112 |
} |
0 | 1113 |
} |
1114 |
||
1316 | 1115 |
bool ReadLanguagePack(int lang_index) |
1116 |
{ |
|
0 | 1117 |
int tot_count, i; |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1118 |
LanguagePack *lang_pack; |
0 | 1119 |
size_t len; |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1120 |
char **langpack_offs; |
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1121 |
char *s; |
0 | 1122 |
|
1123 |
{ |
|
1124 |
char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
|
1125 |
lang_pack = ReadFileToMem(lang, &len, 100000); |
|
1126 |
free(lang); |
|
1127 |
} |
|
1128 |
if (lang_pack == NULL) return false; |
|
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1129 |
if (len < sizeof(LanguagePack) || |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1130 |
lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1131 |
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
0 | 1132 |
free(lang_pack); |
1133 |
return false; |
|
1134 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
1135 |
|
0 | 1136 |
#if defined(TTD_BIG_ENDIAN) |
1316 | 1137 |
for (i = 0; i != 32; i++) { |
2966
7f382cfeb93d
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2957
diff
changeset
|
1138 |
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]); |
0 | 1139 |
} |
1140 |
#endif |
|
1141 |
||
1142 |
tot_count = 0; |
|
1316 | 1143 |
for (i = 0; i != 32; i++) { |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1144 |
uint num = lang_pack->offsets[i]; |
0 | 1145 |
_langtab_start[i] = tot_count; |
1146 |
_langtab_num[i] = num; |
|
1147 |
tot_count += num; |
|
1148 |
} |
|
1149 |
||
1150 |
// Allocate offsets |
|
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1151 |
langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
0 | 1152 |
|
1153 |
// Fill offsets |
|
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1154 |
s = lang_pack->data; |
1316 | 1155 |
for (i = 0; i != tot_count; i++) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1156 |
len = (byte)*s; |
1316 | 1157 |
*s++ = '\0'; // zero terminate the string before. |
1158 |
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
|
0 | 1159 |
langpack_offs[i] = s; |
1160 |
s += len; |
|
1161 |
} |
|
1162 |
||
1321 | 1163 |
free(_langpack); |
0 | 1164 |
_langpack = lang_pack; |
1165 |
||
1321 | 1166 |
free(_langpack_offs); |
0 | 1167 |
_langpack_offs = langpack_offs; |
1168 |
||
1169 |
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); |
|
1170 |
||
1171 |
_dynlang.curr = lang_index; |
|
3601
ac6df06db648
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
1172 |
SetCurrentGrfLangID(_langpack->isocode); |
0 | 1173 |
return true; |
1174 |
} |
|
1175 |
||
3329
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1176 |
/** Determine the current charset based on the environment |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1177 |
* First check some default values, after this one we passed ourselves |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1178 |
* and if none exist return the value for $LANG |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1179 |
* @param environment variable to check conditionally if default ones are not |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1180 |
* set. Pass NULL if you don't want additional checks. |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1181 |
* @return return string containing current charset, or NULL if not-determinable */ |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1182 |
const char *GetCurrentLocale(const char *param) |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1183 |
{ |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1184 |
const char *env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1185 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1186 |
env = getenv("LANGUAGE"); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1187 |
if (env != NULL) return env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1188 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1189 |
env = getenv("LC_ALL"); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1190 |
if (env != NULL) return env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1191 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1192 |
if (param != NULL) { |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1193 |
env = getenv(param); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1194 |
if (env != NULL) return env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1195 |
} |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1196 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1197 |
return getenv("LANG"); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1198 |
} |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1199 |
|
4219
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1200 |
static int CDECL LanguageCompareFunc(const void *a, const void *b) |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1201 |
{ |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1202 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1203 |
} |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1204 |
|
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1205 |
static int GetLanguageList(char **languages, int max) |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1206 |
{ |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1207 |
DIR *dir; |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1208 |
struct dirent *dirent; |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1209 |
int num = 0; |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1210 |
|
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1211 |
dir = opendir(_path.lang_dir); |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1212 |
if (dir != NULL) { |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1213 |
while ((dirent = readdir(dir)) != NULL) { |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1214 |
char *t = strrchr(dirent->d_name, '.'); |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1215 |
|
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1216 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1217 |
languages[num++] = strdup(dirent->d_name); |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1218 |
if (num == max) break; |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1219 |
} |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1220 |
} |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1221 |
closedir(dir); |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1222 |
} |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1223 |
|
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1224 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1225 |
return num; |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1226 |
} |
4211284f29ec
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1227 |
|
0 | 1228 |
// make a list of the available language packs. put the data in _dynlang struct. |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
1229 |
void InitializeLanguagePacks(void) |
0 | 1230 |
{ |
1231 |
DynamicLanguages *dl = &_dynlang; |
|
1321 | 1232 |
int i; |
1233 |
int n; |
|
1234 |
int m; |
|
1235 |
int def; |
|
4505
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1236 |
int def2; |
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1237 |
int fallback; |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1238 |
LanguagePack hdr; |
0 | 1239 |
FILE *in; |
1240 |
char *files[32]; |
|
4505
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1241 |
const char* lang; |
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1242 |
|
4505
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1243 |
lang = GetCurrentLocale("LC_MESSAGES"); |
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1244 |
if (lang == NULL) lang = "en_GB"; |
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1245 |
|
0 | 1246 |
n = GetLanguageList(files, lengthof(files)); |
1247 |
||
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1248 |
def = -1; |
4505
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1249 |
def2 = -1; |
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1250 |
fallback = 0; |
0 | 1251 |
|
1252 |
// go through the language files and make sure that they are valid. |
|
1316 | 1253 |
for (i = m = 0; i != n; i++) { |
4321
b763b7007162
(svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents:
4293
diff
changeset
|
1254 |
size_t j; |
1321 | 1255 |
|
0 | 1256 |
char *s = str_fmt("%s%s", _path.lang_dir, files[i]); |
1257 |
in = fopen(s, "rb"); |
|
1258 |
free(s); |
|
1316 | 1259 |
if (in == NULL || |
0 | 1260 |
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 || |
1261 |
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
|
1262 |
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
|
1263 |
free(files[i]); |
|
1264 |
continue; |
|
1265 |
} |
|
1266 |
||
1267 |
dl->ent[m].file = files[i]; |
|
1268 |
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
|
1269 |
|
4505
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1270 |
if (strcmp(hdr.isocode, "en_GB") == 0) fallback = m; |
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1271 |
if (strncmp(hdr.isocode, lang, 2) == 0) def2 = m; |
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1272 |
if (strncmp(hdr.isocode, lang, 5) == 0) def = m; |
0 | 1273 |
|
1274 |
m++; |
|
1275 |
} |
|
4505
f87e0c7fdda1
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1276 |
if (def == -1) def = (def2 != -1 ? def2 : fallback); |
0 | 1277 |
|
1278 |
if (m == 0) |
|
1279 |
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
|
1280 |
|
0 | 1281 |
dl->num = m; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
1282 |
for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; |
0 | 1283 |
dl->dropdown[i] = INVALID_STRING_ID; |
1284 |
||
1316 | 1285 |
for (i = 0; i != dl->num; i++) |
1286 |
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) { |
|
0 | 1287 |
def = i; |
1288 |
break; |
|
1289 |
} |
|
1290 |
||
1291 |
if (!ReadLanguagePack(def)) |
|
1292 |
error("can't read language pack '%s'", dl->ent[def].file); |
|
2075
7f0ca01392db
(svn r2585) - Fix [Makefile]: some small cleanups, remove warnings, and add mersenne to makefile (Luca)
Darkvater
parents:
2070
diff
changeset
|
1293 |
} |