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