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