author | miham |
Wed, 17 Aug 2005 12:30:07 +0000 | |
changeset 2349 | df02d0ffb588 |
parent 2291 | 2b064aa97f91 |
child 2353 | 076e9b569f64 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1853
diff
changeset
|
4 |
#include "openttd.h" |
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2257
diff
changeset
|
5 |
#include "currency.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.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
|
7 |
#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
|
8 |
#include "strings.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
504
diff
changeset
|
9 |
#include "table/strings.h" |
1306
40038dfdf3ba
(svn r1810) Move town name generation declarations into a header of their own
tron
parents:
1102
diff
changeset
|
10 |
#include "namegen.h" |
0 | 11 |
#include "station.h" |
12 |
#include "town.h" |
|
13 |
#include "vehicle.h" |
|
6
e9b56d50aa99
(svn r7) -Feature [1003350] Euro introduction news item. (dominik81)
darkvater
parents:
0
diff
changeset
|
14 |
#include "news.h" |
430 | 15 |
#include "screenshot.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1376
diff
changeset
|
16 |
#include "waypoint.h" |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
17 |
#include "industry.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
18 |
#include "variables.h" |
0 | 19 |
|
2201 | 20 |
char _userstring[128]; |
21 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
22 |
static char *StationGetSpecialString(char *buff, int x); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
23 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
24 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv); |
0 | 25 |
|
2087 | 26 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei); |
0 | 27 |
|
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
|
28 |
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
|
29 |
|
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
30 |
typedef struct LanguagePack { |
0 | 31 |
uint32 ident; |
32 |
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
|
33 |
char name[32]; // the international name of this language |
|
34 |
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
|
35 |
char isocode[16]; // the ISO code for the language (not country code) |
0 | 36 |
uint16 offsets[32]; // the offsets |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
37 |
byte plural_form; // how to compute plural forms |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
38 |
byte pad[3]; // pad header to be a multiple of 4 |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
39 |
char data[VARARRAY_SIZE]; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
40 |
} LanguagePack; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
41 |
|
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
42 |
static char **_langpack_offs; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
43 |
static LanguagePack *_langpack; |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
44 |
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
|
45 |
static uint _langtab_start[32]; // Offset into langpack offs |
0 | 46 |
|
1321 | 47 |
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = { |
1316 | 48 |
{ /* LT_NORMAL */ |
49 |
STR_PASSENGERS, |
|
50 |
STR_TONS, |
|
51 |
STR_BAGS, |
|
52 |
STR_LITERS, |
|
53 |
STR_ITEMS, |
|
54 |
STR_CRATES, |
|
55 |
STR_TONS, |
|
56 |
STR_TONS, |
|
57 |
STR_TONS, |
|
58 |
STR_TONS, |
|
59 |
STR_BAGS, |
|
60 |
STR_RES_OTHER |
|
61 |
}, |
|
62 |
||
63 |
{ /* LT_HILLY */ |
|
64 |
STR_PASSENGERS, |
|
65 |
STR_TONS, |
|
66 |
STR_BAGS, |
|
67 |
STR_LITERS, |
|
68 |
STR_ITEMS, |
|
69 |
STR_CRATES, |
|
70 |
STR_TONS, |
|
71 |
STR_TONS, |
|
72 |
STR_RES_OTHER, |
|
73 |
STR_TONS, |
|
74 |
STR_BAGS, |
|
75 |
STR_TONS |
|
76 |
}, |
|
77 |
||
78 |
{ /* LT_DESERT */ |
|
79 |
STR_PASSENGERS, |
|
80 |
STR_LITERS, |
|
81 |
STR_BAGS, |
|
82 |
STR_LITERS, |
|
83 |
STR_TONS, |
|
84 |
STR_CRATES, |
|
85 |
STR_TONS, |
|
86 |
STR_TONS, |
|
87 |
STR_TONS, |
|
88 |
STR_LITERS, |
|
89 |
STR_BAGS, |
|
90 |
STR_TONS |
|
91 |
}, |
|
92 |
||
93 |
{ /* LT_CANDY */ |
|
94 |
STR_PASSENGERS, |
|
95 |
STR_TONS, |
|
96 |
STR_BAGS, |
|
97 |
STR_NOTHING, |
|
98 |
STR_NOTHING, |
|
99 |
STR_TONS, |
|
100 |
STR_TONS, |
|
101 |
STR_LITERS, |
|
102 |
STR_TONS, |
|
103 |
STR_NOTHING, |
|
104 |
STR_LITERS, |
|
105 |
STR_NOTHING |
|
106 |
} |
|
0 | 107 |
}; |
108 |
||
109 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
110 |
// Read an int64 from the argv array. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
111 |
static inline int64 GetInt64(const int32 **argv) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
112 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
113 |
int64 result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
114 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
115 |
assert(argv); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
116 |
result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
117 |
(*argv)+=2; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
118 |
return result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
119 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
120 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
121 |
// Read an int32 from the argv array. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
122 |
static inline int32 GetInt32(const int32 **argv) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
123 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
124 |
assert(argv); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
125 |
return *(*argv)++; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
126 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
127 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
128 |
// Read an array from the argv array. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
129 |
static inline const int32 *GetArgvPtr(const int32 **argv, int n) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
130 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
131 |
const int32 *result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
132 |
assert(*argv); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
133 |
result = *argv; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
134 |
(*argv) += n; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
135 |
return result; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
136 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
137 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
138 |
|
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
|
139 |
#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
|
140 |
|
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
|
141 |
// 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
|
142 |
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
|
143 |
|
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
|
144 |
// 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
|
145 |
// 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
|
146 |
// 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
|
147 |
// 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
|
148 |
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
|
149 |
|
1321 | 150 |
static const char *GetStringPtr(StringID string) |
0 | 151 |
{ |
152 |
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; |
|
153 |
} |
|
154 |
||
2087 | 155 |
// The highest 8 bits of string contain the "case index". |
156 |
// These 8 bits will only be set when FormatString wants to print |
|
157 |
// the string in a different case. No one else except FormatString |
|
158 |
// should set those bits. |
|
159 |
char *GetStringWithArgs(char *buffr, uint string, const int32 *argv) |
|
0 | 160 |
{ |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2131
diff
changeset
|
161 |
uint index = GB(string, 0, 11); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2131
diff
changeset
|
162 |
uint tab = GB(string, 11, 5); |
0 | 163 |
|
2087 | 164 |
if (!(string & 0xFFFF)) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
165 |
error("!invalid string id 0 in GetString"); |
1321 | 166 |
} |
0 | 167 |
|
1321 | 168 |
switch (tab) { |
169 |
case 4: |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
170 |
if (index >= 0xC0) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
171 |
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv)); |
1321 | 172 |
break; |
173 |
||
174 |
case 14: |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
175 |
if (index >= 0xE4) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
176 |
return GetSpecialPlayerNameString(buffr, index - 0xE4, argv); |
1321 | 177 |
break; |
178 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
179 |
// User defined name |
1321 | 180 |
case 15: |
181 |
return GetName(index, buffr); |
|
182 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
183 |
case 31: |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
184 |
// dynamic strings. These are NOT to be passed through the formatter, |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
185 |
// but passed through verbatim. |
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
|
186 |
if (index < (STR_SPEC_USERSTRING & 0x7FF)) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
187 |
return strecpy(buffr, _bound_strings[index], NULL); |
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
|
188 |
} |
1321 | 189 |
|
2087 | 190 |
return FormatString(buffr, _userstring, NULL, 0); |
0 | 191 |
} |
192 |
||
193 |
if (index >= _langtab_num[tab]) |
|
1321 | 194 |
error( |
195 |
"!String 0x%X is invalid. " |
|
196 |
"Probably because an old version of the .lng file.\n", string |
|
197 |
); |
|
0 | 198 |
|
2087 | 199 |
return FormatString(buffr, GetStringPtr(string&0xFFFF), argv, string >> 24); |
0 | 200 |
} |
201 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
202 |
char *GetString(char *buffr, StringID string) |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
203 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
204 |
return GetStringWithArgs(buffr, string, (int32*)_decode_parameters); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
205 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
206 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
207 |
|
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
|
208 |
// 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
|
209 |
// 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
|
210 |
// 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
|
211 |
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
|
212 |
{ |
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
|
213 |
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
|
214 |
_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
|
215 |
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
|
216 |
} |
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
|
217 |
|
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
|
218 |
// 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
|
219 |
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
|
220 |
{ |
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
|
221 |
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
|
222 |
} |
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
|
223 |
|
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
|
224 |
void InjectDParam(int amount) |
0 | 225 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
226 |
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); |
0 | 227 |
} |
228 |
||
229 |
static const uint32 _divisor_table[] = { |
|
230 |
1000000000, |
|
231 |
100000000, |
|
232 |
10000000, |
|
233 |
1000000, |
|
234 |
||
235 |
100000, |
|
236 |
10000, |
|
237 |
1000, |
|
238 |
100, |
|
239 |
10, |
|
240 |
1 |
|
241 |
}; |
|
242 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
243 |
static char *FormatCommaNumber(char *buff, int32 number) |
0 | 244 |
{ |
245 |
uint32 quot,divisor; |
|
246 |
int i; |
|
247 |
uint32 tot; |
|
248 |
uint32 num; |
|
249 |
||
250 |
if (number < 0) { |
|
251 |
*buff++ = '-'; |
|
252 |
number = -number; |
|
253 |
} |
|
254 |
||
255 |
num = number; |
|
256 |
||
257 |
tot = 0; |
|
1316 | 258 |
for (i = 0; i != 10; i++) { |
0 | 259 |
divisor = _divisor_table[i]; |
260 |
quot = 0; |
|
261 |
if (num >= divisor) { |
|
262 |
quot = num / _divisor_table[i]; |
|
263 |
num = num % _divisor_table[i]; |
|
264 |
} |
|
1316 | 265 |
if (tot |= quot || i == 9) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
266 |
*buff++ = '0' + quot; |
1316 | 267 |
if (i == 0 || i == 3 || i == 6) *buff++ = ','; |
0 | 268 |
} |
269 |
} |
|
270 |
||
1316 | 271 |
*buff = '\0'; |
0 | 272 |
|
273 |
return buff; |
|
274 |
} |
|
275 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
276 |
static char *FormatNoCommaNumber(char *buff, int32 number) |
0 | 277 |
{ |
278 |
uint32 quot,divisor; |
|
279 |
int i; |
|
280 |
uint32 tot; |
|
281 |
uint32 num; |
|
282 |
||
283 |
if (number < 0) { |
|
284 |
*buff++ = '-'; |
|
285 |
number = -number; |
|
286 |
} |
|
287 |
||
288 |
num = number; |
|
289 |
||
290 |
tot = 0; |
|
1316 | 291 |
for (i = 0; i != 10; i++) { |
0 | 292 |
divisor = _divisor_table[i]; |
293 |
quot = 0; |
|
294 |
if (num >= divisor) { |
|
295 |
quot = num / _divisor_table[i]; |
|
296 |
num = num % _divisor_table[i]; |
|
297 |
} |
|
1316 | 298 |
if (tot |= quot || i == 9) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
299 |
*buff++ = '0' + quot; |
0 | 300 |
} |
301 |
} |
|
302 |
||
1316 | 303 |
*buff = '\0'; |
0 | 304 |
|
305 |
return buff; |
|
306 |
} |
|
307 |
||
308 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
309 |
static char *FormatYmdString(char *buff, uint16 number) |
0 | 310 |
{ |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
311 |
const char *src; |
0 | 312 |
YearMonthDay ymd; |
313 |
||
314 |
ConvertDayToYMD(&ymd, number); |
|
315 |
||
1316 | 316 |
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
|
317 |
|
0 | 318 |
buff[-1] = ' '; |
319 |
memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4); |
|
320 |
buff[3] = ' '; |
|
321 |
||
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
|
322 |
return FormatNoCommaNumber(buff+4, ymd.year + MAX_YEAR_BEGIN_REAL); |
0 | 323 |
} |
324 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
325 |
static char *FormatMonthAndYear(char *buff, uint16 number) |
0 | 326 |
{ |
327 |
const char *src; |
|
328 |
YearMonthDay ymd; |
|
329 |
||
330 |
ConvertDayToYMD(&ymd, number); |
|
331 |
||
1316 | 332 |
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
0 | 333 |
buff[-1] = ' '; |
334 |
||
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
|
335 |
return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); |
0 | 336 |
} |
337 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
338 |
static char *FormatTinyDate(char *buff, uint16 number) |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
339 |
{ |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
340 |
YearMonthDay ymd; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
341 |
|
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
342 |
ConvertDayToYMD(&ymd, number); |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
343 |
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
|
344 |
|
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
345 |
return buff; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
346 |
} |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
347 |
|
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
348 |
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact) |
0 | 349 |
{ |
350 |
const char *s; |
|
351 |
char c; |
|
352 |
char buf[40], *p; |
|
353 |
int j; |
|
354 |
||
355 |
// multiply by exchange rate |
|
356 |
number *= spec->rate; |
|
357 |
||
358 |
// convert from negative |
|
1316 | 359 |
if (number < 0) { |
360 |
*buff++ = '-'; |
|
361 |
number = -number; |
|
362 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
363 |
|
788
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
364 |
// add prefix part |
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
365 |
s = spec->prefix; |
1316 | 366 |
while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c; |
0 | 367 |
|
368 |
// for huge numbers, compact the number into k or M |
|
369 |
if (compact) { |
|
370 |
compact = 0; |
|
371 |
if (number >= 1000000000) { |
|
372 |
number = (number + 500000) / 1000000; |
|
373 |
compact = 'M'; |
|
374 |
} else if (number >= 1000000) { |
|
375 |
number = (number + 500) / 1000; |
|
376 |
compact = 'k'; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
377 |
} |
0 | 378 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
379 |
|
0 | 380 |
// convert to ascii number and add commas |
381 |
p = buf; |
|
382 |
j = 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
383 |
do { |
1316 | 384 |
if (--j == 0) { |
385 |
*p++ = spec->separator; |
|
386 |
j = 3; |
|
387 |
} |
|
0 | 388 |
*p++ = '0' + number % 10; |
389 |
} while (number /= 10); |
|
390 |
do *buff++ = *--p; while (p != buf); |
|
391 |
||
392 |
if (compact) *buff++ = compact; |
|
393 |
||
788
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
394 |
// add suffix part |
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
395 |
s = spec->suffix; |
1316 | 396 |
while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c; |
0 | 397 |
|
398 |
return buff; |
|
399 |
} |
|
400 |
||
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
401 |
static int DeterminePluralForm(int32 n) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
402 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
403 |
// The absolute value determines plurality |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
404 |
if (n < 0) n = -n; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
405 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
406 |
switch(_langpack->plural_form) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
407 |
// Two forms, singular used for one only |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
408 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
409 |
// Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
410 |
// Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
411 |
case 0: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
412 |
default: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
413 |
return n != 1; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
414 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
415 |
// Only one form |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
416 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
417 |
// Hungarian, Japanese, Korean, Turkish |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
418 |
case 1: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
419 |
return 0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
420 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
421 |
// Two forms, singular used for zero and one |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
422 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
423 |
// French, Brazilian Portuguese |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
424 |
case 2: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
425 |
return n > 1; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
426 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
427 |
// Three forms, special case for zero |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
428 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
429 |
// Latvian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
430 |
case 3: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
431 |
return n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
432 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
433 |
// Three forms, special case for one and two |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
434 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
435 |
// Gaelige (Irish) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
436 |
case 4: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
437 |
return n==1 ? 0 : n==2 ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
438 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
439 |
// Three forms, special case for numbers ending in 1[2-9] |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
440 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
441 |
// Lithuanian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
442 |
case 5: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
443 |
return n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
444 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
445 |
// Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4] |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
446 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
447 |
// Croatian, Czech, Russian, Slovak, Ukrainian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
448 |
case 6: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
449 |
return n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
450 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
451 |
// Three forms, special case for one and some numbers ending in 2, 3, or 4 |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
452 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
453 |
// Polish |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
454 |
case 7: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
455 |
return n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
456 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
457 |
// Four forms, special case for one and all numbers ending in 02, 03, or 04 |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
458 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
459 |
// Slovenian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
460 |
case 8: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
461 |
return n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
462 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
463 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
464 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
465 |
static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
466 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
467 |
//<NUM> {Length of each string} {each string} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
468 |
uint n = (byte)*b++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
469 |
uint pos,i, mylen=0,mypos=0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
470 |
for(i=pos=0; i!=n; i++) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
471 |
uint len = (byte)*b++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
472 |
if (i == form) { |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
473 |
mypos = pos; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
474 |
mylen = len; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
475 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
476 |
pos += len; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
477 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
478 |
*dstlen = mylen; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
479 |
memcpy(dst, b + mypos, mylen); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
480 |
return b + pos; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
481 |
} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
482 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
483 |
|
2087 | 484 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei) |
0 | 485 |
{ |
486 |
byte b; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
487 |
const int32 *argv_orig = argv; |
2087 | 488 |
uint modifier = 0; |
0 | 489 |
|
1316 | 490 |
while ((b = *str++) != '\0') { |
491 |
switch (b) { |
|
0 | 492 |
case 0x1: // {SETX} |
493 |
*buff++ = b; |
|
494 |
*buff++ = *str++; |
|
495 |
break; |
|
496 |
case 0x2: // {SETXY} |
|
497 |
*buff++ = b; |
|
498 |
*buff++ = *str++; |
|
499 |
*buff++ = *str++; |
|
500 |
break; |
|
2057
898a905490f1
(svn r2566) Rename COMMA{8,16,32} to just COMMA, because it's the same anyway
tron
parents:
2056
diff
changeset
|
501 |
case 0x7B: // {COMMA} |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
502 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
503 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
504 |
case 0x7C: // Move argument pointer |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
505 |
argv = argv_orig + (byte)*str++; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
506 |
break; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
507 |
case 0x7D: { // {P} |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
508 |
int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
509 |
int len; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
510 |
str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len); |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
511 |
buff += len; |
0 | 512 |
break; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
513 |
} |
2087 | 514 |
case 0x7E: // {NUM} |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
515 |
buff = FormatNoCommaNumber(buff, GetInt32(&argv)); |
0 | 516 |
break; |
517 |
case 0x7F: // {CURRENCY} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
518 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt32(&argv), false); |
0 | 519 |
break; |
520 |
// 0x80 is reserved for EURO |
|
521 |
case 0x81: // {STRINL} |
|
522 |
str += 2; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
523 |
buff = GetStringWithArgs(buff, READ_LE_UINT16(str-2), argv); |
0 | 524 |
break; |
525 |
case 0x82: // {DATE_LONG} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
526 |
buff = FormatYmdString(buff, GetInt32(&argv)); |
0 | 527 |
break; |
528 |
case 0x83: // {DATE_SHORT} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
529 |
buff = FormatMonthAndYear(buff, GetInt32(&argv)); |
0 | 530 |
break; |
531 |
case 0x84: {// {VELOCITY} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
532 |
int value = GetInt32(&argv); |
1704
2525507adda7
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
533 |
if (_opt_ptr->kilometers) value = value * 1648 >> 10; |
0 | 534 |
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
|
535 |
if (_opt_ptr->kilometers) { |
0 | 536 |
memcpy(buff, " km/h", 5); |
537 |
buff += 5; |
|
538 |
} else { |
|
539 |
memcpy(buff, " mph", 4); |
|
540 |
buff += 4; |
|
541 |
} |
|
542 |
break; |
|
543 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
544 |
// 0x85 is used as escape character.. |
0 | 545 |
case 0x85: |
1316 | 546 |
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
|
547 |
case 0: /* {CURRCOMPACT} */ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
548 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt32(&argv), true); |
0 | 549 |
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
|
550 |
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
|
551 |
buff = strecpy(buff, _openttd_revision, NULL); |
0 | 552 |
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
|
553 |
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
|
554 |
// Short description of cargotypes. Layout: |
0 | 555 |
// 8-bit = cargo type |
556 |
// 16-bit = cargo count |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
557 |
StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][GetInt32(&argv)]; |
0 | 558 |
uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1; |
559 |
// liquid type of cargo is multiplied by 100 to get correct amount |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
560 |
buff = FormatCommaNumber(buff, GetInt32(&argv) * 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
|
561 |
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
|
562 |
buff = strecpy(buff, GetStringPtr(cargo_str), NULL); |
1316 | 563 |
} break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
564 |
case 4: {/* {CURRCOMPACT64} */ |
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
|
565 |
// 64 bit compact currency-unit |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
566 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt64(&argv), true); |
0 | 567 |
break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
568 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
569 |
case 5: { /* {STRING1} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
570 |
// String that consumes ONE argument |
2087 | 571 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
572 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1)); |
2087 | 573 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
574 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
575 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
576 |
case 6: { /* {STRING2} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
577 |
// String that consumes TWO arguments |
2087 | 578 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
579 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2)); |
2087 | 580 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
581 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
582 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
583 |
case 7: { /* {STRING3} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
584 |
// String that consumes THREE arguments |
2087 | 585 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
586 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3)); |
2087 | 587 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
588 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
589 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
590 |
case 8: { /* {STRING4} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
591 |
// String that consumes FOUR arguments |
2087 | 592 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
593 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4)); |
2087 | 594 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
595 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
596 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
597 |
case 9: { /* {STRING5} */ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
598 |
// String that consumes FIVE arguments |
2087 | 599 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
600 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5)); |
2087 | 601 |
modifier = 0; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
602 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
603 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
604 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
605 |
case 10: { /* {STATIONFEATURES} */ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
606 |
buff = StationGetSpecialString(buff, GetInt32(&argv)); |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
607 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
608 |
} |
0 | 609 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
610 |
case 11: { /* {INDUSTRY} */ |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
611 |
Industry *i = GetIndustry(GetInt32(&argv)); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
612 |
int32 args[2]; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
613 |
|
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
614 |
// industry not valid anymore? |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
615 |
if (i->xy == 0) |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
616 |
break; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
617 |
|
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
618 |
// First print the town name and the industry type name |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
619 |
// The string STR_INDUSTRY_PATTERN controls the formatting |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
620 |
args[0] = i->town->index; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
621 |
args[1] = i->type + STR_4802_COAL_MINE; |
2087 | 622 |
buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24); |
623 |
modifier = 0; |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
624 |
break; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
625 |
} |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
626 |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
627 |
case 12: { // {VOLUME} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
628 |
buff = FormatCommaNumber(buff, GetInt32(&argv) * 1000); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
629 |
buff = strecpy(buff, " ", NULL); |
2087 | 630 |
buff = FormatString(buff, GetStringPtr(STR_LITERS), NULL, modifier >> 24); |
631 |
modifier = 0; |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
632 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
633 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
634 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
635 |
case 13: { // {G 0 Der Die Das} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
636 |
byte *s = (byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
637 |
int len; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
638 |
int gender = 0; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
639 |
if (s && s[0] == 0x87) |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
640 |
gender = s[1]; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
641 |
str = ParseStringChoice(str, gender, buff, &len); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
642 |
buff += len; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
643 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
644 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
645 |
|
2087 | 646 |
case 14: { // {DATE_TINY} |
647 |
buff = FormatTinyDate(buff, GetInt32(&argv)); |
|
648 |
break; |
|
649 |
} |
|
650 |
||
651 |
case 15: { // {CARGO} |
|
652 |
// Layout now is: |
|
653 |
// 8bit - cargo type |
|
654 |
// 16-bit - cargo count |
|
655 |
StringID cargo_str = _cargoc.names_long[GetInt32(&argv)]; |
|
2131
525edb393b81
(svn r2641) Fix: [strings] forgot to increase argv pointer twice for {CARGO}
ludde
parents:
2122
diff
changeset
|
656 |
buff = GetStringWithArgs(buff, cargo_str, argv++); |
2087 | 657 |
break; |
658 |
} |
|
659 |
||
0 | 660 |
default: |
661 |
error("!invalid escape sequence in string"); |
|
662 |
} |
|
663 |
break; |
|
664 |
||
665 |
case 0x86: // {SKIP} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
666 |
argv++; |
0 | 667 |
break; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
668 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
669 |
// This sets up the gender for the string. |
2087 | 670 |
// We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
671 |
case 0x87: // {GENDER 0} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
672 |
str++; |
0 | 673 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
674 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
675 |
case 0x88: {// {STRING} |
2087 | 676 |
uint str = modifier + GetInt32(&argv); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
677 |
// WARNING. It's prohibited for the included string to consume any arguments. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
678 |
// For included strings that consume argument, you should use STRING1, STRING2 etc. |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
679 |
// To debug stuff you can set argv to NULL and it will tell you |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
680 |
buff = GetStringWithArgs(buff, str, argv); |
2087 | 681 |
modifier = 0; |
0 | 682 |
break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
683 |
} |
0 | 684 |
|
2087 | 685 |
case 0x99: { // {WAYPOINT} |
686 |
int32 temp[2]; |
|
687 |
Waypoint *wp = GetWaypoint(GetInt32(&argv)); |
|
688 |
StringID str; |
|
689 |
if (wp->string != STR_NULL) { |
|
690 |
str = wp->string; |
|
691 |
} else { |
|
692 |
temp[0] = wp->town_index; |
|
693 |
temp[1] = wp->town_cn + 1; |
|
694 |
str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; |
|
695 |
} |
|
696 |
buff = GetStringWithArgs(buff, str, temp); |
|
697 |
} break; |
|
0 | 698 |
|
699 |
case 0x9A: { // {STATION} |
|
700 |
Station *st; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
701 |
int32 temp[2]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
702 |
|
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
703 |
st = GetStation(GetInt32(&argv)); |
1316 | 704 |
if (st->xy == 0) { // station doesn't exist anymore |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
705 |
buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL); |
64
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
706 |
break; |
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
707 |
} |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
708 |
temp[0] = st->town->townnametype; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
709 |
temp[1] = st->town->townnameparts; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
710 |
buff = GetStringWithArgs(buff, st->string_id, temp); |
0 | 711 |
break; |
712 |
} |
|
713 |
case 0x9B: { // {TOWN} |
|
714 |
Town *t; |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
715 |
int32 temp[1]; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
716 |
t = GetTown(GetInt32(&argv)); |
0 | 717 |
assert(t->xy); |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
718 |
temp[0] = t->townnameparts; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
719 |
buff = GetStringWithArgs(buff, t->townnametype, temp); |
0 | 720 |
break; |
721 |
} |
|
722 |
||
723 |
case 0x9C: { // {CURRENCY64} |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
724 |
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetInt64(&argv), false); |
0 | 725 |
break; |
726 |
} |
|
727 |
||
2087 | 728 |
case 0x9D: { // {SETCASE} |
729 |
// This is a pseudo command, it's outputted when someone does {STRING.ack} |
|
730 |
// The modifier is added to all subsequent GetStringWithArgs that accept the modifier. |
|
731 |
modifier = (byte)*str++ << 24; |
|
732 |
break; |
|
733 |
} |
|
734 |
||
735 |
case 0x9E: { // {Used to implement case switching} |
|
736 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
|
737 |
// Each LEN is printed using 2 bytes in big endian order. |
|
738 |
uint num = (byte)*str++; |
|
739 |
while (num) { |
|
2107
607a900aefa3
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2087
diff
changeset
|
740 |
if ((byte)str[0] == casei) { |
2087 | 741 |
// Found the case, adjust str pointer and continue |
742 |
str += 3; |
|
743 |
break; |
|
744 |
} |
|
745 |
// Otherwise skip to the next case |
|
746 |
str += 3 + (str[1] << 8) + str[2]; |
|
747 |
num--; |
|
0 | 748 |
} |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
749 |
break; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
750 |
} |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
751 |
|
0 | 752 |
// case 0x88..0x98: // {COLORS} |
753 |
// case 0xE: // {TINYFONT} |
|
754 |
// case 0xF: // {BIGFONT} |
|
755 |
// 0x9E is the highest number that is available. |
|
756 |
default: |
|
757 |
*buff++ = b; |
|
758 |
} |
|
759 |
} |
|
1316 | 760 |
*buff = '\0'; |
0 | 761 |
return buff; |
762 |
} |
|
763 |
||
764 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
765 |
static char *StationGetSpecialString(char *buff, int x) |
0 | 766 |
{ |
1316 | 767 |
if (x & 0x01) *buff++ = '\xB4'; |
768 |
if (x & 0x02) *buff++ = '\xB5'; |
|
769 |
if (x & 0x04) *buff++ = '\xB6'; |
|
770 |
if (x & 0x08) *buff++ = '\xB7'; |
|
771 |
if (x & 0x10) *buff++ = '\xB8'; |
|
772 |
*buff = '\0'; |
|
0 | 773 |
return buff; |
774 |
} |
|
775 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
776 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed) |
1316 | 777 |
{ |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
778 |
_town_name_generators[ind](buff, seed); |
0 | 779 |
|
1316 | 780 |
while (*buff != '\0') buff++; |
0 | 781 |
return buff; |
782 |
} |
|
783 |
||
784 |
static const char * const _silly_company_names[] = { |
|
785 |
"Bloggs Brothers", |
|
786 |
"Tiny Transport Ltd.", |
|
787 |
"Express Travel", |
|
788 |
"Comfy-Coach & Co.", |
|
789 |
"Crush & Bump Ltd.", |
|
790 |
"Broken & Late Ltd.", |
|
791 |
"Sam Speedy & Son", |
|
792 |
"Supersonic Travel", |
|
793 |
"Mike's Motors", |
|
794 |
"Lightning International", |
|
795 |
"Pannik & Loozit Ltd.", |
|
796 |
"Inter-City Transport", |
|
797 |
"Getout & Pushit Ltd.", |
|
798 |
}; |
|
799 |
||
800 |
static const char * const _surname_list[] = { |
|
801 |
"Adams", |
|
802 |
"Allan", |
|
803 |
"Baker", |
|
804 |
"Bigwig", |
|
805 |
"Black", |
|
806 |
"Bloggs", |
|
807 |
"Brown", |
|
808 |
"Campbell", |
|
809 |
"Gordon", |
|
810 |
"Hamilton", |
|
811 |
"Hawthorn", |
|
812 |
"Higgins", |
|
813 |
"Green", |
|
814 |
"Gribble", |
|
815 |
"Jones", |
|
816 |
"McAlpine", |
|
817 |
"MacDonald", |
|
818 |
"McIntosh", |
|
819 |
"Muir", |
|
820 |
"Murphy", |
|
821 |
"Nelson", |
|
822 |
"O'Donnell", |
|
823 |
"Parker", |
|
824 |
"Phillips", |
|
825 |
"Pilkington", |
|
826 |
"Quigley", |
|
827 |
"Sharkey", |
|
828 |
"Thomson", |
|
829 |
"Watkins", |
|
830 |
"Grumpy", |
|
831 |
"Dozy", |
|
832 |
"Speedy", |
|
833 |
"Nosey", |
|
834 |
"Dribble", |
|
835 |
"Mushroom", |
|
836 |
"Cabbage", |
|
837 |
"Sniffle", |
|
838 |
"Fishy", |
|
839 |
"Swindle", |
|
840 |
"Sneaky", |
|
841 |
"Nutkins", |
|
842 |
}; |
|
843 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
844 |
static const char _initial_name_letters[] = { |
1321 | 845 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', |
846 |
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', |
|
0 | 847 |
}; |
848 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
849 |
static char *GenAndCoName(char *buff, uint32 arg) |
0 | 850 |
{ |
851 |
uint base,num; |
|
852 |
||
853 |
base = 0; |
|
854 |
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
|
855 |
if (_opt_ptr->landscape == LT_CANDY) { |
0 | 856 |
base = num; |
857 |
num = 12; |
|
858 |
} |
|
859 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
860 |
buff = strecpy(buff, _surname_list[base + (num * GB(arg, 16, 8) >> 8)], NULL); |
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
|
861 |
buff = strecpy(buff, " & Co.", NULL); |
0 | 862 |
|
863 |
return buff; |
|
864 |
} |
|
865 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
866 |
static char *GenPresidentName(char *buff, uint32 x) |
0 | 867 |
{ |
868 |
uint i, base, num; |
|
869 |
||
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
870 |
buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8]; |
0 | 871 |
buff[1] = '.'; |
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
872 |
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
|
873 |
buff += 3; |
0 | 874 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
875 |
i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8; |
0 | 876 |
if (i < sizeof(_initial_name_letters)) { |
877 |
buff[0] = _initial_name_letters[i]; |
|
878 |
buff[1] = '.'; |
|
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
879 |
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
|
880 |
buff += 3; |
0 | 881 |
} |
882 |
||
883 |
base = 0; |
|
884 |
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
|
885 |
if (_opt_ptr->landscape == LT_CANDY) { |
0 | 886 |
base = num; |
887 |
num = 12; |
|
888 |
} |
|
889 |
||
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
|
890 |
buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL); |
0 | 891 |
|
892 |
return buff; |
|
893 |
} |
|
894 |
||
895 |
static const char * const _song_names[] = { |
|
896 |
"Tycoon DELUXE Theme", |
|
897 |
"Easy Driver", |
|
898 |
"Little Red Diesel", |
|
899 |
"Cruise Control", |
|
900 |
"Don't Walk!", |
|
901 |
"Fell Apart On Me", |
|
902 |
"City Groove", |
|
903 |
"Funk Central", |
|
904 |
"Stoke It", |
|
905 |
"Road Hog", |
|
906 |
"Aliens Ate My Railway", |
|
907 |
"Snarl Up", |
|
908 |
"Stroll On", |
|
909 |
"Can't Get There From Here", |
|
910 |
"Sawyer's Tune", |
|
911 |
"Hold That Train!", |
|
912 |
"Movin' On", |
|
913 |
"Goss Groove", |
|
914 |
"Small Town", |
|
915 |
"Broomer's Oil Rag", |
|
916 |
"Jammit", |
|
917 |
"Hard Drivin'" |
|
918 |
}; |
|
919 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
920 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) |
0 | 921 |
{ |
1316 | 922 |
switch (ind) { |
1321 | 923 |
case 1: // not used |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
924 |
return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], NULL); |
0 | 925 |
|
1321 | 926 |
case 2: // used for Foobar & Co company names |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
927 |
return GenAndCoName(buff, GetInt32(&argv)); |
0 | 928 |
|
1321 | 929 |
case 3: // President name |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
930 |
return GenPresidentName(buff, GetInt32(&argv)); |
0 | 931 |
|
1321 | 932 |
case 4: // song names |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
933 |
return strecpy(buff, _song_names[GetInt32(&argv) - 1], NULL); |
0 | 934 |
} |
935 |
||
936 |
// town name? |
|
1316 | 937 |
if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) { |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
938 |
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv)); |
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
|
939 |
return strecpy(buff, " Transport", NULL); |
0 | 940 |
} |
941 |
||
942 |
// language name? |
|
943 |
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
|
944 |
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
|
945 |
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
|
946 |
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL); |
0 | 947 |
} |
948 |
||
949 |
// resolution size? |
|
950 |
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
|
951 |
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
|
952 |
return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]); |
|
953 |
} |
|
954 |
||
955 |
// screenshot format name? |
|
956 |
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { |
|
957 |
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
|
958 |
return strecpy(buff, GetScreenshotFormatDesc(i), NULL); |
0 | 959 |
} |
960 |
||
961 |
assert(0); |
|
962 |
return NULL; |
|
963 |
} |
|
964 |
||
965 |
// remap a string ID from the old format to the new format |
|
966 |
StringID RemapOldStringID(StringID s) |
|
967 |
{ |
|
1321 | 968 |
switch (s) { |
969 |
case 0x0006: return STR_SV_EMPTY; |
|
970 |
case 0x7000: return STR_SV_UNNAMED; |
|
971 |
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
972 |
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
973 |
case 0x8864: return STR_SV_TRAIN_NAME; |
|
974 |
case 0x902B: return STR_SV_ROADVEH_NAME; |
|
975 |
case 0x9830: return STR_SV_SHIP_NAME; |
|
976 |
case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
977 |
||
978 |
default: |
|
979 |
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) |
|
980 |
return s - 0x300F + STR_SV_STNAME; |
|
981 |
else |
|
982 |
return s; |
|
983 |
} |
|
0 | 984 |
} |
985 |
||
1316 | 986 |
bool ReadLanguagePack(int lang_index) |
987 |
{ |
|
0 | 988 |
int tot_count, i; |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
989 |
LanguagePack *lang_pack; |
0 | 990 |
size_t len; |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
991 |
char **langpack_offs; |
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
992 |
char *s; |
0 | 993 |
|
994 |
{ |
|
995 |
char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
|
996 |
lang_pack = ReadFileToMem(lang, &len, 100000); |
|
997 |
free(lang); |
|
998 |
} |
|
999 |
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
|
1000 |
if (len < sizeof(LanguagePack) || |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1001 |
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
|
1002 |
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
0 | 1003 |
free(lang_pack); |
1004 |
return false; |
|
1005 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
1006 |
|
0 | 1007 |
#if defined(TTD_BIG_ENDIAN) |
1316 | 1008 |
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
|
1009 |
lang_pack->offsets[i] = READ_LE_UINT16(&lang_pack->offsets[i]); |
0 | 1010 |
} |
1011 |
#endif |
|
1012 |
||
1013 |
tot_count = 0; |
|
1316 | 1014 |
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
|
1015 |
uint num = lang_pack->offsets[i]; |
0 | 1016 |
_langtab_start[i] = tot_count; |
1017 |
_langtab_num[i] = num; |
|
1018 |
tot_count += num; |
|
1019 |
} |
|
1020 |
||
1021 |
// Allocate offsets |
|
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1022 |
langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
0 | 1023 |
|
1024 |
// Fill offsets |
|
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1025 |
s = lang_pack->data; |
1316 | 1026 |
for (i = 0; i != tot_count; i++) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1027 |
len = (byte)*s; |
1316 | 1028 |
*s++ = '\0'; // zero terminate the string before. |
1029 |
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
|
0 | 1030 |
langpack_offs[i] = s; |
1031 |
s += len; |
|
1032 |
} |
|
1033 |
||
1321 | 1034 |
free(_langpack); |
0 | 1035 |
_langpack = lang_pack; |
1036 |
||
1321 | 1037 |
free(_langpack_offs); |
0 | 1038 |
_langpack_offs = langpack_offs; |
1039 |
||
1040 |
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); |
|
1041 |
||
1042 |
||
1043 |
_dynlang.curr = lang_index; |
|
1044 |
return true; |
|
1045 |
} |
|
1046 |
||
1047 |
// 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
|
1048 |
void InitializeLanguagePacks(void) |
0 | 1049 |
{ |
1050 |
DynamicLanguages *dl = &_dynlang; |
|
1321 | 1051 |
int i; |
1052 |
int n; |
|
1053 |
int m; |
|
1054 |
int def; |
|
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1055 |
int fallback; |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1056 |
LanguagePack hdr; |
0 | 1057 |
FILE *in; |
1058 |
char *files[32]; |
|
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1059 |
uint j; |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1060 |
|
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1061 |
char lang[] = "en"; |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1062 |
static const char* env[] = { |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1063 |
"LANGUAGE", |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1064 |
"LC_ALL", |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1065 |
"LC_MESSAGES", |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1066 |
"LANG" |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1067 |
}; |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1068 |
|
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1069 |
for (j = 0; j < lengthof(env); j++) { |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1070 |
const char* envlang = getenv(env[j]); |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1071 |
if (envlang != NULL) { |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1072 |
snprintf(lang, lengthof(lang), "%.2s", envlang); |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1073 |
break; |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1074 |
} |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1075 |
} |
0 | 1076 |
|
1077 |
n = GetLanguageList(files, lengthof(files)); |
|
1078 |
||
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1079 |
def = -1; |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1080 |
fallback = 0; |
0 | 1081 |
|
1082 |
// go through the language files and make sure that they are valid. |
|
1316 | 1083 |
for (i = m = 0; i != n; i++) { |
1321 | 1084 |
int j; |
1085 |
||
0 | 1086 |
char *s = str_fmt("%s%s", _path.lang_dir, files[i]); |
1087 |
in = fopen(s, "rb"); |
|
1088 |
free(s); |
|
1316 | 1089 |
if (in == NULL || |
0 | 1090 |
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 || |
1091 |
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
|
1092 |
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
|
1093 |
free(files[i]); |
|
1094 |
continue; |
|
1095 |
} |
|
1096 |
||
1097 |
dl->ent[m].file = files[i]; |
|
1098 |
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
|
1099 |
|
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1100 |
if (strcmp(hdr.name, "English") == 0) fallback = m; |
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1101 |
if (strcmp(hdr.isocode, lang) == 0) def = m; |
0 | 1102 |
|
1103 |
m++; |
|
1104 |
} |
|
2257
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1105 |
if (def == -1) def = fallback; |
0 | 1106 |
|
1107 |
if (m == 0) |
|
1108 |
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
|
1109 |
|
0 | 1110 |
dl->num = m; |
1316 | 1111 |
for (i = 0; i != dl->num; i++) |
0 | 1112 |
dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; |
1113 |
dl->dropdown[i] = INVALID_STRING_ID; |
|
1114 |
||
1316 | 1115 |
for (i = 0; i != dl->num; i++) |
1116 |
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) { |
|
0 | 1117 |
def = i; |
1118 |
break; |
|
1119 |
} |
|
1120 |
||
1121 |
if (!ReadLanguagePack(def)) |
|
1122 |
error("can't read language pack '%s'", dl->ent[def].file); |
|
2075
7f0ca01392db
(svn r2585) - Fix [Makefile]: some small cleanups, remove warnings, and add mersenne to makefile (Luca)
Darkvater
parents:
2070
diff
changeset
|
1123 |
} |
7f0ca01392db
(svn r2585) - Fix [Makefile]: some small cleanups, remove warnings, and add mersenne to makefile (Luca)
Darkvater
parents:
2070
diff
changeset
|
1124 |