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