author | tron |
Sun, 06 Feb 2005 20:53:31 +0000 | |
changeset 1328 | eacd8225ed42 |
parent 1321 | 1373f60f4b39 |
child 1376 | d4e1dd8eb7e5 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1317
3c90086ff34f
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1316
diff
changeset
|
3 |
#include "string.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1306
diff
changeset
|
4 |
#include "strings.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
504
diff
changeset
|
5 |
#include "table/strings.h" |
1306
7768d8361d88
(svn r1810) Move town name generation declarations into a header of their own
tron
parents:
1102
diff
changeset
|
6 |
#include "namegen.h" |
0 | 7 |
#include "station.h" |
8 |
#include "town.h" |
|
9 |
#include "vehicle.h" |
|
6
e9b56d50aa99
(svn r7) -Feature [1003350] Euro introduction news item. (dominik81)
darkvater
parents:
0
diff
changeset
|
10 |
#include "news.h" |
430 | 11 |
#include "screenshot.h" |
0 | 12 |
|
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
13 |
static char *StationGetSpecialString(char *buff); |
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
14 |
static char *GetSpecialTownNameString(char *buff, int ind); |
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
15 |
static char *GetSpecialPlayerNameString(char *buff, int ind); |
0 | 16 |
|
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
17 |
static char *DecodeString(char *buff, const char *str); |
0 | 18 |
|
663
80c66fd07863
(svn r1098) -Fix: server without revision build doesn't care about the client's version. Also moved all revision things where it belongs (network.c)
darkvater
parents:
659
diff
changeset
|
19 |
extern const char _openttd_revision[]; |
659
a9733f856cd0
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents:
656
diff
changeset
|
20 |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
21 |
typedef struct LanguagePack { |
0 | 22 |
uint32 ident; |
23 |
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
|
24 |
char name[32]; // the international name of this language |
|
25 |
char own_name[32]; // the localized name of this language |
|
26 |
uint16 offsets[32]; // the offsets |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
27 |
char data[VARARRAY_SIZE]; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
28 |
} LanguagePack; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
29 |
|
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
30 |
static char **_langpack_offs; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
31 |
static LanguagePack *_langpack; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
32 |
static uint _langtab_num[32]; // Offset into langpack offs |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
33 |
static uint _langtab_start[32]; // Offset into langpack offs |
0 | 34 |
|
1321 | 35 |
const StringID _currency_string_list[] = { |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
36 |
STR_CURR_GBP, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
37 |
STR_CURR_USD, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
38 |
STR_CURR_EUR, |
0 | 39 |
STR_CURR_YEN, |
40 |
STR_CURR_ATS, |
|
41 |
STR_CURR_BEF, |
|
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
42 |
STR_CURR_CHF, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
43 |
STR_CURR_CZK, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
44 |
STR_CURR_DEM, |
0 | 45 |
STR_CURR_DKK, |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
46 |
STR_CURR_ESP, |
0 | 47 |
STR_CURR_FIM, |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
48 |
STR_CURR_FRF, |
0 | 49 |
STR_CURR_GRD, |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
50 |
STR_CURR_HUF, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
51 |
STR_CURR_ISK, |
0 | 52 |
STR_CURR_ITL, |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
53 |
STR_CURR_NLG, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
54 |
STR_CURR_NOK, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
55 |
STR_CURR_PLN, |
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
56 |
STR_CURR_ROL, |
0 | 57 |
STR_CURR_RUR, |
762
ef014856bd88
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
58 |
STR_CURR_SEK, |
759
a445474d7c21
(svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
663
diff
changeset
|
59 |
STR_CURR_CUSTOM, |
0 | 60 |
INVALID_STRING_ID |
61 |
}; |
|
62 |
||
1321 | 63 |
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = { |
1316 | 64 |
{ /* LT_NORMAL */ |
65 |
STR_PASSENGERS, |
|
66 |
STR_TONS, |
|
67 |
STR_BAGS, |
|
68 |
STR_LITERS, |
|
69 |
STR_ITEMS, |
|
70 |
STR_CRATES, |
|
71 |
STR_TONS, |
|
72 |
STR_TONS, |
|
73 |
STR_TONS, |
|
74 |
STR_TONS, |
|
75 |
STR_BAGS, |
|
76 |
STR_RES_OTHER |
|
77 |
}, |
|
78 |
||
79 |
{ /* LT_HILLY */ |
|
80 |
STR_PASSENGERS, |
|
81 |
STR_TONS, |
|
82 |
STR_BAGS, |
|
83 |
STR_LITERS, |
|
84 |
STR_ITEMS, |
|
85 |
STR_CRATES, |
|
86 |
STR_TONS, |
|
87 |
STR_TONS, |
|
88 |
STR_RES_OTHER, |
|
89 |
STR_TONS, |
|
90 |
STR_BAGS, |
|
91 |
STR_TONS |
|
92 |
}, |
|
93 |
||
94 |
{ /* LT_DESERT */ |
|
95 |
STR_PASSENGERS, |
|
96 |
STR_LITERS, |
|
97 |
STR_BAGS, |
|
98 |
STR_LITERS, |
|
99 |
STR_TONS, |
|
100 |
STR_CRATES, |
|
101 |
STR_TONS, |
|
102 |
STR_TONS, |
|
103 |
STR_TONS, |
|
104 |
STR_LITERS, |
|
105 |
STR_BAGS, |
|
106 |
STR_TONS |
|
107 |
}, |
|
108 |
||
109 |
{ /* LT_CANDY */ |
|
110 |
STR_PASSENGERS, |
|
111 |
STR_TONS, |
|
112 |
STR_BAGS, |
|
113 |
STR_NOTHING, |
|
114 |
STR_NOTHING, |
|
115 |
STR_TONS, |
|
116 |
STR_TONS, |
|
117 |
STR_LITERS, |
|
118 |
STR_TONS, |
|
119 |
STR_NOTHING, |
|
120 |
STR_LITERS, |
|
121 |
STR_NOTHING |
|
122 |
} |
|
0 | 123 |
}; |
124 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
125 |
static char *str_cat(char *dst, const char *src) |
0 | 126 |
{ |
1316 | 127 |
while ((*dst++ = *src++) != '\0') {} |
0 | 128 |
return dst - 1; |
129 |
} |
|
130 |
||
1321 | 131 |
static const char *GetStringPtr(StringID string) |
0 | 132 |
{ |
133 |
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; |
|
134 |
} |
|
135 |
||
1321 | 136 |
char *GetString(char *buffr, StringID string) |
0 | 137 |
{ |
138 |
uint index = string & 0x7FF; |
|
139 |
uint tab = string >> 11; |
|
140 |
||
1321 | 141 |
switch (string) { |
142 |
case 0: |
|
143 |
error("!invalid string id 0 in GetString"); |
|
144 |
break; |
|
0 | 145 |
|
1321 | 146 |
case 0x30D1: |
147 |
return StationGetSpecialString(buffr); |
|
0 | 148 |
|
1321 | 149 |
case STR_SPEC_SCREENSHOT_NAME: |
150 |
return DecodeString(buffr, _screenshot_name); |
|
151 |
} |
|
0 | 152 |
|
1321 | 153 |
switch (tab) { |
154 |
case 4: |
|
155 |
if (index >= 0xC0) return GetSpecialTownNameString(buffr, index - 0xC0); |
|
156 |
break; |
|
157 |
||
158 |
case 14: |
|
159 |
if (index >= 0xE4) return GetSpecialPlayerNameString(buffr, index - 0xE4); |
|
160 |
break; |
|
161 |
||
162 |
case 15: |
|
163 |
return GetName(index, buffr); |
|
164 |
||
165 |
case 31: // special or dynamic strings |
|
166 |
return DecodeString(buffr, _userstring); |
|
167 |
||
168 |
default: |
|
169 |
break; |
|
0 | 170 |
} |
171 |
||
172 |
if (index >= _langtab_num[tab]) |
|
1321 | 173 |
error( |
174 |
"!String 0x%X is invalid. " |
|
175 |
"Probably because an old version of the .lng file.\n", string |
|
176 |
); |
|
0 | 177 |
|
178 |
return DecodeString(buffr, GetStringPtr(string)); |
|
179 |
} |
|
180 |
||
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1306
diff
changeset
|
181 |
void InjectDParam(int amount) |
0 | 182 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
183 |
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); |
0 | 184 |
} |
185 |
||
186 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
187 |
int32 GetParamInt32(void) |
0 | 188 |
{ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
189 |
int32 result = GetDParam(0); |
425 | 190 |
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1)); |
0 | 191 |
return result; |
192 |
} |
|
193 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
194 |
static int64 GetParamInt64(void) |
0 | 195 |
{ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
196 |
int64 result = GetDParam(0) + ((uint64)GetDParam(1) << 32); |
425 | 197 |
memmove(&_decode_parameters[0], &_decode_parameters[2], sizeof(uint32) * (lengthof(_decode_parameters)-2)); |
0 | 198 |
return result; |
199 |
} |
|
200 |
||
201 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
202 |
int GetParamInt16(void) |
0 | 203 |
{ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
204 |
int result = (int16)GetDParam(0); |
425 | 205 |
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1)); |
0 | 206 |
return result; |
207 |
} |
|
208 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
209 |
int GetParamInt8(void) |
0 | 210 |
{ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
211 |
int result = (int8)GetDParam(0); |
425 | 212 |
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1)); |
0 | 213 |
return result; |
214 |
} |
|
215 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
216 |
int GetParamUint16(void) |
0 | 217 |
{ |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
218 |
int result = GetDParam(0); |
425 | 219 |
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1)); |
0 | 220 |
return result; |
221 |
} |
|
222 |
||
223 |
static const uint32 _divisor_table[] = { |
|
224 |
1000000000, |
|
225 |
100000000, |
|
226 |
10000000, |
|
227 |
1000000, |
|
228 |
||
229 |
100000, |
|
230 |
10000, |
|
231 |
1000, |
|
232 |
100, |
|
233 |
10, |
|
234 |
1 |
|
235 |
}; |
|
236 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
237 |
static char *FormatCommaNumber(char *buff, int32 number) |
0 | 238 |
{ |
239 |
uint32 quot,divisor; |
|
240 |
int i; |
|
241 |
uint32 tot; |
|
242 |
uint32 num; |
|
243 |
||
244 |
if (number < 0) { |
|
245 |
*buff++ = '-'; |
|
246 |
number = -number; |
|
247 |
} |
|
248 |
||
249 |
num = number; |
|
250 |
||
251 |
tot = 0; |
|
1316 | 252 |
for (i = 0; i != 10; i++) { |
0 | 253 |
divisor = _divisor_table[i]; |
254 |
quot = 0; |
|
255 |
if (num >= divisor) { |
|
256 |
quot = num / _divisor_table[i]; |
|
257 |
num = num % _divisor_table[i]; |
|
258 |
} |
|
1316 | 259 |
if (tot |= quot || i == 9) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
260 |
*buff++ = '0' + quot; |
1316 | 261 |
if (i == 0 || i == 3 || i == 6) *buff++ = ','; |
0 | 262 |
} |
263 |
} |
|
264 |
||
1316 | 265 |
*buff = '\0'; |
0 | 266 |
|
267 |
return buff; |
|
268 |
} |
|
269 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
270 |
static char *FormatNoCommaNumber(char *buff, int32 number) |
0 | 271 |
{ |
272 |
uint32 quot,divisor; |
|
273 |
int i; |
|
274 |
uint32 tot; |
|
275 |
uint32 num; |
|
276 |
||
277 |
if (number < 0) { |
|
278 |
*buff++ = '-'; |
|
279 |
number = -number; |
|
280 |
} |
|
281 |
||
282 |
num = number; |
|
283 |
||
284 |
tot = 0; |
|
1316 | 285 |
for (i = 0; i != 10; i++) { |
0 | 286 |
divisor = _divisor_table[i]; |
287 |
quot = 0; |
|
288 |
if (num >= divisor) { |
|
289 |
quot = num / _divisor_table[i]; |
|
290 |
num = num % _divisor_table[i]; |
|
291 |
} |
|
1316 | 292 |
if (tot |= quot || i == 9) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
293 |
*buff++ = '0' + quot; |
0 | 294 |
} |
295 |
} |
|
296 |
||
1316 | 297 |
*buff = '\0'; |
0 | 298 |
|
299 |
return buff; |
|
300 |
} |
|
301 |
||
302 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
303 |
static char *FormatYmdString(char *buff, uint16 number) |
0 | 304 |
{ |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
305 |
const char *src; |
0 | 306 |
YearMonthDay ymd; |
307 |
||
308 |
ConvertDayToYMD(&ymd, number); |
|
309 |
||
1316 | 310 |
for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
311 |
|
0 | 312 |
buff[-1] = ' '; |
313 |
memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4); |
|
314 |
buff[3] = ' '; |
|
315 |
||
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
919
diff
changeset
|
316 |
return FormatNoCommaNumber(buff+4, ymd.year + MAX_YEAR_BEGIN_REAL); |
0 | 317 |
} |
318 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
319 |
static char *FormatMonthAndYear(char *buff, uint16 number) |
0 | 320 |
{ |
321 |
const char *src; |
|
322 |
YearMonthDay ymd; |
|
323 |
||
324 |
ConvertDayToYMD(&ymd, number); |
|
325 |
||
1316 | 326 |
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
0 | 327 |
buff[-1] = ' '; |
328 |
||
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
919
diff
changeset
|
329 |
return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); |
0 | 330 |
} |
331 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
332 |
static char *FormatTinyDate(char *buff, uint16 number) |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
333 |
{ |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
334 |
YearMonthDay ymd; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
335 |
|
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
336 |
ConvertDayToYMD(&ymd, number); |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
337 |
buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL); |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
338 |
|
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
339 |
return buff; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
340 |
} |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
341 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
342 |
uint GetCurrentCurrencyRate(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
343 |
{ |
1316 | 344 |
return _currency_specs[_opt.currency].rate; |
26 | 345 |
} |
346 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
347 |
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact) |
0 | 348 |
{ |
349 |
const char *s; |
|
350 |
char c; |
|
351 |
char buf[40], *p; |
|
352 |
int j; |
|
353 |
||
354 |
// multiply by exchange rate |
|
355 |
number *= spec->rate; |
|
356 |
||
357 |
// convert from negative |
|
1316 | 358 |
if (number < 0) { |
359 |
*buff++ = '-'; |
|
360 |
number = -number; |
|
361 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
362 |
|
788
951b52443d48
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
363 |
// add prefix part |
951b52443d48
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
364 |
s = spec->prefix; |
1316 | 365 |
while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c; |
0 | 366 |
|
367 |
// for huge numbers, compact the number into k or M |
|
368 |
if (compact) { |
|
369 |
compact = 0; |
|
370 |
if (number >= 1000000000) { |
|
371 |
number = (number + 500000) / 1000000; |
|
372 |
compact = 'M'; |
|
373 |
} else if (number >= 1000000) { |
|
374 |
number = (number + 500) / 1000; |
|
375 |
compact = 'k'; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
376 |
} |
0 | 377 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
378 |
|
0 | 379 |
// convert to ascii number and add commas |
380 |
p = buf; |
|
381 |
j = 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
382 |
do { |
1316 | 383 |
if (--j == 0) { |
384 |
*p++ = spec->separator; |
|
385 |
j = 3; |
|
386 |
} |
|
0 | 387 |
*p++ = '0' + number % 10; |
388 |
} while (number /= 10); |
|
389 |
do *buff++ = *--p; while (p != buf); |
|
390 |
||
391 |
if (compact) *buff++ = compact; |
|
392 |
||
788
951b52443d48
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
393 |
// add suffix part |
951b52443d48
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
394 |
s = spec->suffix; |
1316 | 395 |
while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c; |
0 | 396 |
|
397 |
return buff; |
|
398 |
} |
|
399 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
400 |
static char *DecodeString(char *buff, const char *str) |
0 | 401 |
{ |
402 |
byte b; |
|
403 |
||
1316 | 404 |
while ((b = *str++) != '\0') { |
405 |
switch (b) { |
|
0 | 406 |
case 0x1: // {SETX} |
407 |
*buff++ = b; |
|
408 |
*buff++ = *str++; |
|
409 |
break; |
|
410 |
case 0x2: // {SETXY} |
|
411 |
*buff++ = b; |
|
412 |
*buff++ = *str++; |
|
413 |
*buff++ = *str++; |
|
414 |
break; |
|
415 |
case 0x7B: // {COMMA32} |
|
416 |
buff = FormatCommaNumber(buff, GetParamInt32()); |
|
417 |
break; |
|
418 |
case 0x7C: // {COMMA16} |
|
419 |
buff = FormatCommaNumber(buff, GetParamInt16()); |
|
420 |
break; |
|
421 |
case 0x7D: // {COMMA8} |
|
422 |
buff = FormatCommaNumber(buff, GetParamInt8()); |
|
423 |
break; |
|
424 |
case 0x7E: // {NUMU16} |
|
425 |
buff = FormatNoCommaNumber(buff, GetParamInt16()); |
|
426 |
break; |
|
427 |
case 0x7F: // {CURRENCY} |
|
428 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), false); |
|
429 |
break; |
|
430 |
// 0x80 is reserved for EURO |
|
431 |
case 0x81: // {STRINL} |
|
432 |
str += 2; |
|
433 |
buff = GetString(buff, READ_LE_UINT16(str-2)); |
|
434 |
break; |
|
435 |
case 0x82: // {DATE_LONG} |
|
436 |
buff = FormatYmdString(buff, GetParamUint16()); |
|
437 |
break; |
|
438 |
case 0x83: // {DATE_SHORT} |
|
439 |
buff = FormatMonthAndYear(buff, GetParamUint16()); |
|
440 |
break; |
|
441 |
case 0x84: {// {VELOCITY} |
|
442 |
int value = GetParamInt16(); |
|
443 |
if (_opt.kilometers) value = value * 1648 >> 10; |
|
444 |
buff = FormatCommaNumber(buff, value); |
|
445 |
if (_opt.kilometers) { |
|
446 |
memcpy(buff, " km/h", 5); |
|
447 |
buff += 5; |
|
448 |
} else { |
|
449 |
memcpy(buff, " mph", 4); |
|
450 |
buff += 4; |
|
451 |
} |
|
452 |
break; |
|
453 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
454 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
455 |
// 0x85 is used as escape character.. |
0 | 456 |
case 0x85: |
1316 | 457 |
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
|
458 |
case 0: /* {CURRCOMPACT} */ |
0 | 459 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), true); |
460 |
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
|
461 |
case 1: /* {INT32} */ |
0 | 462 |
buff = FormatNoCommaNumber(buff, GetParamInt32()); |
463 |
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
|
464 |
case 2: /* {REV} */ |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
465 |
buff = str_cat(buff, _openttd_revision); |
0 | 466 |
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
|
467 |
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
|
468 |
// Short description of cargotypes. Layout: |
0 | 469 |
// 8-bit = cargo type |
470 |
// 16-bit = cargo count |
|
1318 | 471 |
const char *s; |
1321 | 472 |
StringID cargo_str = _cargo_string_list[_opt.landscape][(byte)GetParamInt8()]; |
0 | 473 |
uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1; |
474 |
// liquid type of cargo is multiplied by 100 to get correct amount |
|
1316 | 475 |
buff = FormatCommaNumber(buff, GetParamInt16() * multiplier); |
0 | 476 |
s = GetStringPtr(cargo_str); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
477 |
|
0 | 478 |
memcpy(buff++, " ", 1); |
479 |
while (*s) *buff++ = *s++; |
|
1316 | 480 |
} 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
|
481 |
case 4: /* {CURRCOMPACT64} */ |
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
|
482 |
// 64 bit compact currency-unit |
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
|
483 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), true); |
0 | 484 |
break; |
485 |
||
486 |
default: |
|
487 |
error("!invalid escape sequence in string"); |
|
488 |
} |
|
489 |
break; |
|
490 |
||
491 |
case 0x86: // {SKIP} |
|
492 |
GetParamInt16(); |
|
493 |
//assert(0); |
|
494 |
break; |
|
495 |
case 0x87: { // {VOLUME} |
|
1318 | 496 |
const char *s; |
0 | 497 |
buff = FormatCommaNumber(buff, GetParamInt16() * 1000); |
498 |
memcpy(buff++, " ", 1); |
|
499 |
s = GetStringPtr(STR_LITERS); |
|
500 |
while (*s) *buff++ = *s++; |
|
501 |
break; |
|
502 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
503 |
|
0 | 504 |
case 0x88: // {STRING} |
505 |
buff = GetString(buff, (uint16)GetParamUint16()); |
|
506 |
break; |
|
507 |
||
508 |
case 0x99: { // {CARGO} |
|
509 |
// Layout now is: |
|
510 |
// 8bit - cargo type |
|
511 |
// 16-bit - cargo count |
|
512 |
int cargo_str = _cargoc.names_long_s[GetParamInt8()]; |
|
513 |
// Now check if the cargo count is 1, if it is, increase string by 32. |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
514 |
if (GetDParam(0) != 1) cargo_str += 32; |
0 | 515 |
buff = GetString(buff, cargo_str); |
516 |
break; |
|
517 |
} |
|
518 |
||
519 |
case 0x9A: { // {STATION} |
|
520 |
Station *st; |
|
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1306
diff
changeset
|
521 |
InjectDParam(1); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
788
diff
changeset
|
522 |
st = GetStation(GetDParam(1)); |
1316 | 523 |
if (st->xy == 0) { // station doesn't exist anymore |
64
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
524 |
buff = GetString(buff, STR_UNKNOWN_DESTINATION); |
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
525 |
break; |
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
526 |
} |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
527 |
SetDParam(0, st->town->townnametype); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
528 |
SetDParam(1, st->town->townnameparts); |
0 | 529 |
buff = GetString(buff, st->string_id); |
530 |
break; |
|
531 |
} |
|
532 |
case 0x9B: { // {TOWN} |
|
533 |
Town *t; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
788
diff
changeset
|
534 |
t = GetTown(GetDParam(0)); |
0 | 535 |
assert(t->xy); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
536 |
SetDParam(0, t->townnameparts); |
0 | 537 |
buff = GetString(buff, t->townnametype); |
538 |
break; |
|
539 |
} |
|
540 |
||
541 |
case 0x9C: { // {CURRENCY64} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
542 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), false); |
0 | 543 |
break; |
544 |
} |
|
545 |
||
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
287
diff
changeset
|
546 |
case 0x9D: { // {WAYPOINT} |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
547 |
Waypoint *cp = &_waypoints[GetDParam(0)]; |
0 | 548 |
StringID str; |
549 |
int idx; |
|
550 |
if (~cp->town_or_string & 0xC000) { |
|
551 |
GetParamInt32(); // skip it |
|
552 |
str = cp->town_or_string; |
|
553 |
} else { |
|
554 |
idx = (cp->town_or_string >> 8) & 0x3F; |
|
555 |
if (idx == 0) { |
|
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
287
diff
changeset
|
556 |
str = STR_WAYPOINTNAME_CITY; |
0 | 557 |
} else { |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1306
diff
changeset
|
558 |
InjectDParam(1); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
559 |
SetDParam(1, idx + 1); |
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
287
diff
changeset
|
560 |
str = STR_WAYPOINTNAME_CITY_SERIAL; |
0 | 561 |
} |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
562 |
SetDParam(0, cp->town_or_string & 0xFF); |
0 | 563 |
} |
564 |
||
565 |
buff = GetString(buff, str); |
|
566 |
} break; |
|
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
567 |
|
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
568 |
case 0x9E: { // {DATE_TINY} |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
569 |
buff = FormatTinyDate(buff, GetParamUint16()); |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
570 |
break; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
571 |
} |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
572 |
|
0 | 573 |
// case 0x88..0x98: // {COLORS} |
574 |
// case 0xE: // {TINYFONT} |
|
575 |
// case 0xF: // {BIGFONT} |
|
576 |
// 0x9E is the highest number that is available. |
|
577 |
default: |
|
578 |
*buff++ = b; |
|
579 |
} |
|
580 |
} |
|
1316 | 581 |
*buff = '\0'; |
0 | 582 |
return buff; |
583 |
} |
|
584 |
||
585 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
586 |
static char *StationGetSpecialString(char *buff) |
0 | 587 |
{ |
588 |
int x = GetParamInt8(); |
|
1316 | 589 |
if (x & 0x01) *buff++ = '\xB4'; |
590 |
if (x & 0x02) *buff++ = '\xB5'; |
|
591 |
if (x & 0x04) *buff++ = '\xB6'; |
|
592 |
if (x & 0x08) *buff++ = '\xB7'; |
|
593 |
if (x & 0x10) *buff++ = '\xB8'; |
|
594 |
*buff = '\0'; |
|
0 | 595 |
return buff; |
596 |
} |
|
597 |
||
1316 | 598 |
static char *GetSpecialTownNameString(char *buff, int ind) |
599 |
{ |
|
0 | 600 |
uint32 x = GetParamInt32(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
601 |
|
0 | 602 |
_town_name_generators[ind](buff, x); |
603 |
||
1316 | 604 |
while (*buff != '\0') buff++; |
0 | 605 |
return buff; |
606 |
} |
|
607 |
||
608 |
static const char * const _silly_company_names[] = { |
|
609 |
"Bloggs Brothers", |
|
610 |
"Tiny Transport Ltd.", |
|
611 |
"Express Travel", |
|
612 |
"Comfy-Coach & Co.", |
|
613 |
"Crush & Bump Ltd.", |
|
614 |
"Broken & Late Ltd.", |
|
615 |
"Sam Speedy & Son", |
|
616 |
"Supersonic Travel", |
|
617 |
"Mike's Motors", |
|
618 |
"Lightning International", |
|
619 |
"Pannik & Loozit Ltd.", |
|
620 |
"Inter-City Transport", |
|
621 |
"Getout & Pushit Ltd.", |
|
622 |
}; |
|
623 |
||
624 |
static const char * const _surname_list[] = { |
|
625 |
"Adams", |
|
626 |
"Allan", |
|
627 |
"Baker", |
|
628 |
"Bigwig", |
|
629 |
"Black", |
|
630 |
"Bloggs", |
|
631 |
"Brown", |
|
632 |
"Campbell", |
|
633 |
"Gordon", |
|
634 |
"Hamilton", |
|
635 |
"Hawthorn", |
|
636 |
"Higgins", |
|
637 |
"Green", |
|
638 |
"Gribble", |
|
639 |
"Jones", |
|
640 |
"McAlpine", |
|
641 |
"MacDonald", |
|
642 |
"McIntosh", |
|
643 |
"Muir", |
|
644 |
"Murphy", |
|
645 |
"Nelson", |
|
646 |
"O'Donnell", |
|
647 |
"Parker", |
|
648 |
"Phillips", |
|
649 |
"Pilkington", |
|
650 |
"Quigley", |
|
651 |
"Sharkey", |
|
652 |
"Thomson", |
|
653 |
"Watkins", |
|
654 |
"Grumpy", |
|
655 |
"Dozy", |
|
656 |
"Speedy", |
|
657 |
"Nosey", |
|
658 |
"Dribble", |
|
659 |
"Mushroom", |
|
660 |
"Cabbage", |
|
661 |
"Sniffle", |
|
662 |
"Fishy", |
|
663 |
"Swindle", |
|
664 |
"Sneaky", |
|
665 |
"Nutkins", |
|
666 |
}; |
|
667 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
668 |
static const char _initial_name_letters[] = { |
1321 | 669 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', |
670 |
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', |
|
0 | 671 |
}; |
672 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
673 |
static char *GenAndCoName(char *buff) |
0 | 674 |
{ |
675 |
uint32 x = GetParamInt32(); |
|
676 |
uint base,num; |
|
677 |
||
678 |
base = 0; |
|
679 |
num = 29; |
|
680 |
if (_opt.landscape == LT_CANDY) { |
|
681 |
base = num; |
|
682 |
num = 12; |
|
683 |
} |
|
684 |
||
685 |
buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]); |
|
686 |
buff = str_cat(buff, " & Co."); |
|
687 |
||
688 |
return buff; |
|
689 |
} |
|
690 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
691 |
static char *GenPlayerName_4(char *buff) |
0 | 692 |
{ |
693 |
uint32 x = GetParamInt32(); |
|
694 |
uint i, base, num; |
|
695 |
||
1316 | 696 |
buff[0] = _initial_name_letters[(sizeof(_initial_name_letters) * (byte)x) >> 8]; |
0 | 697 |
buff[1] = '.'; |
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
698 |
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
|
699 |
buff += 3; |
0 | 700 |
|
701 |
i = ((sizeof(_initial_name_letters) + 35) * (byte)(x >> 8)) >> 8; |
|
702 |
if (i < sizeof(_initial_name_letters)) { |
|
703 |
buff[0] = _initial_name_letters[i]; |
|
704 |
buff[1] = '.'; |
|
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
705 |
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
|
706 |
buff += 3; |
0 | 707 |
} |
708 |
||
709 |
base = 0; |
|
710 |
num = 29; |
|
711 |
if (_opt.landscape == LT_CANDY) { |
|
712 |
base = num; |
|
713 |
num = 12; |
|
714 |
} |
|
715 |
||
716 |
buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]); |
|
717 |
||
718 |
return buff; |
|
719 |
} |
|
720 |
||
721 |
static const char * const _song_names[] = { |
|
722 |
"Tycoon DELUXE Theme", |
|
723 |
"Easy Driver", |
|
724 |
"Little Red Diesel", |
|
725 |
"Cruise Control", |
|
726 |
"Don't Walk!", |
|
727 |
"Fell Apart On Me", |
|
728 |
"City Groove", |
|
729 |
"Funk Central", |
|
730 |
"Stoke It", |
|
731 |
"Road Hog", |
|
732 |
"Aliens Ate My Railway", |
|
733 |
"Snarl Up", |
|
734 |
"Stroll On", |
|
735 |
"Can't Get There From Here", |
|
736 |
"Sawyer's Tune", |
|
737 |
"Hold That Train!", |
|
738 |
"Movin' On", |
|
739 |
"Goss Groove", |
|
740 |
"Small Town", |
|
741 |
"Broomer's Oil Rag", |
|
742 |
"Jammit", |
|
743 |
"Hard Drivin'" |
|
744 |
}; |
|
745 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
746 |
static char *GetSpecialPlayerNameString(char *buff, int ind) |
0 | 747 |
{ |
1316 | 748 |
switch (ind) { |
1321 | 749 |
case 1: // not used |
750 |
return str_cat(buff, _silly_company_names[GetParamInt32() & 0xFFFF]); |
|
0 | 751 |
|
1321 | 752 |
case 2: // used for Foobar & Co company names |
753 |
return GenAndCoName(buff); |
|
0 | 754 |
|
1321 | 755 |
case 3: // President name |
756 |
return GenPlayerName_4(buff); |
|
0 | 757 |
|
1321 | 758 |
case 4: // song names |
759 |
return str_cat(buff, _song_names[GetParamUint16() - 1]); |
|
0 | 760 |
} |
761 |
||
762 |
// town name? |
|
1316 | 763 |
if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) { |
0 | 764 |
buff = GetSpecialTownNameString(buff, ind - 6); |
765 |
return str_cat(buff, " Transport"); |
|
766 |
} |
|
767 |
||
768 |
// language name? |
|
769 |
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
|
770 |
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4); |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
771 |
return str_cat(buff, i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name); |
0 | 772 |
} |
773 |
||
774 |
// resolution size? |
|
775 |
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
|
776 |
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
|
777 |
return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]); |
|
778 |
} |
|
779 |
||
780 |
// screenshot format name? |
|
781 |
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { |
|
782 |
int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4); |
|
783 |
return str_cat(buff, GetScreenshotFormatDesc(i)); |
|
784 |
} |
|
785 |
||
786 |
assert(0); |
|
787 |
return NULL; |
|
788 |
} |
|
789 |
||
790 |
// remap a string ID from the old format to the new format |
|
791 |
StringID RemapOldStringID(StringID s) |
|
792 |
{ |
|
1321 | 793 |
switch (s) { |
794 |
case 0x0006: return STR_SV_EMPTY; |
|
795 |
case 0x7000: return STR_SV_UNNAMED; |
|
796 |
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
797 |
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
798 |
case 0x8864: return STR_SV_TRAIN_NAME; |
|
799 |
case 0x902B: return STR_SV_ROADVEH_NAME; |
|
800 |
case 0x9830: return STR_SV_SHIP_NAME; |
|
801 |
case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
802 |
||
803 |
default: |
|
804 |
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) |
|
805 |
return s - 0x300F + STR_SV_STNAME; |
|
806 |
else |
|
807 |
return s; |
|
808 |
} |
|
0 | 809 |
} |
810 |
||
1316 | 811 |
bool ReadLanguagePack(int lang_index) |
812 |
{ |
|
0 | 813 |
int tot_count, i; |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
814 |
LanguagePack *lang_pack; |
0 | 815 |
size_t len; |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
816 |
char **langpack_offs; |
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
817 |
char *s; |
0 | 818 |
|
819 |
{ |
|
820 |
char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
|
821 |
lang_pack = ReadFileToMem(lang, &len, 100000); |
|
822 |
free(lang); |
|
823 |
} |
|
824 |
if (lang_pack == NULL) return false; |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
825 |
if (len < sizeof(LanguagePack) || |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
826 |
lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
827 |
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
0 | 828 |
free(lang_pack); |
829 |
return false; |
|
830 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
831 |
|
0 | 832 |
#if defined(TTD_BIG_ENDIAN) |
1316 | 833 |
for (i = 0; i != 32; i++) { |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
834 |
lang_pack->offsets[i] = READ_LE_UINT16(&lang_pack->offsets[i]); |
0 | 835 |
} |
836 |
#endif |
|
837 |
||
838 |
tot_count = 0; |
|
1316 | 839 |
for (i = 0; i != 32; i++) { |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
840 |
uint num = lang_pack->offsets[i]; |
0 | 841 |
_langtab_start[i] = tot_count; |
842 |
_langtab_num[i] = num; |
|
843 |
tot_count += num; |
|
844 |
} |
|
845 |
||
846 |
// Allocate offsets |
|
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
847 |
langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
0 | 848 |
|
849 |
// Fill offsets |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
850 |
s = lang_pack->data; |
1316 | 851 |
for (i = 0; i != tot_count; i++) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
852 |
len = (byte)*s; |
1316 | 853 |
*s++ = '\0'; // zero terminate the string before. |
854 |
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
|
0 | 855 |
langpack_offs[i] = s; |
856 |
s += len; |
|
857 |
} |
|
858 |
||
1321 | 859 |
free(_langpack); |
0 | 860 |
_langpack = lang_pack; |
861 |
||
1321 | 862 |
free(_langpack_offs); |
0 | 863 |
_langpack_offs = langpack_offs; |
864 |
||
865 |
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); |
|
866 |
||
867 |
||
868 |
_dynlang.curr = lang_index; |
|
869 |
return true; |
|
870 |
} |
|
871 |
||
872 |
// make a list of the available language packs. put the data in _dynlang struct. |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
970
diff
changeset
|
873 |
void InitializeLanguagePacks(void) |
0 | 874 |
{ |
875 |
DynamicLanguages *dl = &_dynlang; |
|
1321 | 876 |
int i; |
877 |
int n; |
|
878 |
int m; |
|
879 |
int def; |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
880 |
LanguagePack hdr; |
0 | 881 |
FILE *in; |
882 |
char *files[32]; |
|
883 |
||
884 |
n = GetLanguageList(files, lengthof(files)); |
|
885 |
||
886 |
def = 0; // default language file |
|
887 |
||
888 |
// go through the language files and make sure that they are valid. |
|
1316 | 889 |
for (i = m = 0; i != n; i++) { |
1321 | 890 |
int j; |
891 |
||
0 | 892 |
char *s = str_fmt("%s%s", _path.lang_dir, files[i]); |
893 |
in = fopen(s, "rb"); |
|
894 |
free(s); |
|
1316 | 895 |
if (in == NULL || |
0 | 896 |
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 || |
897 |
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
|
898 |
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
|
899 |
free(files[i]); |
|
900 |
continue; |
|
901 |
} |
|
902 |
||
903 |
dl->ent[m].file = files[i]; |
|
904 |
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
|
905 |
|
1316 | 906 |
if (strcmp(hdr.name, "English") == 0) def = m; |
0 | 907 |
|
908 |
m++; |
|
909 |
} |
|
910 |
||
911 |
if (m == 0) |
|
912 |
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
|
913 |
|
0 | 914 |
dl->num = m; |
1316 | 915 |
for (i = 0; i != dl->num; i++) |
0 | 916 |
dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; |
917 |
dl->dropdown[i] = INVALID_STRING_ID; |
|
918 |
||
1316 | 919 |
for (i = 0; i != dl->num; i++) |
920 |
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) { |
|
0 | 921 |
def = i; |
922 |
break; |
|
923 |
} |
|
924 |
||
925 |
if (!ReadLanguagePack(def)) |
|
926 |
error("can't read language pack '%s'", dl->ent[def].file); |
|
927 |
} |