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