author | peter1138 |
Sat, 08 Apr 2006 12:04:23 +0000 | |
changeset 3477 | 80c3465b38ee |
parent 3342 | 0de5e6997611 |
child 3485 | a67571100234 |
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 |
|
2635 | 164 |
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString"); |
0 | 165 |
|
1321 | 166 |
switch (tab) { |
167 |
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
|
168 |
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
|
169 |
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv)); |
1321 | 170 |
break; |
171 |
||
172 |
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
|
173 |
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
|
174 |
return GetSpecialPlayerNameString(buffr, index - 0xE4, argv); |
1321 | 175 |
break; |
176 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
177 |
// User defined name |
1321 | 178 |
case 15: |
179 |
return GetName(index, buffr); |
|
180 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
181 |
case 31: |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
182 |
// 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
|
183 |
// 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
|
184 |
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
|
185 |
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
|
186 |
} |
1321 | 187 |
|
2087 | 188 |
return FormatString(buffr, _userstring, NULL, 0); |
0 | 189 |
} |
190 |
||
2639 | 191 |
if (index >= _langtab_num[tab]) { |
1321 | 192 |
error( |
193 |
"!String 0x%X is invalid. " |
|
194 |
"Probably because an old version of the .lng file.\n", string |
|
195 |
); |
|
2639 | 196 |
} |
0 | 197 |
|
2635 | 198 |
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8)); |
0 | 199 |
} |
200 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
201 |
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
|
202 |
{ |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
203 |
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
|
204 |
} |
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 |
|
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
|
207 |
// 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
|
208 |
// 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
|
209 |
// 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
|
210 |
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
|
211 |
{ |
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 |
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
|
213 |
_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
|
214 |
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
|
215 |
} |
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 |
// 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
|
218 |
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
|
219 |
{ |
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 |
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
|
221 |
} |
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 |
|
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
|
223 |
void InjectDParam(int amount) |
0 | 224 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
225 |
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); |
0 | 226 |
} |
227 |
||
228 |
static const uint32 _divisor_table[] = { |
|
229 |
1000000000, |
|
230 |
100000000, |
|
231 |
10000000, |
|
232 |
1000000, |
|
233 |
||
234 |
100000, |
|
235 |
10000, |
|
236 |
1000, |
|
237 |
100, |
|
238 |
10, |
|
239 |
1 |
|
240 |
}; |
|
241 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
242 |
static char *FormatCommaNumber(char *buff, int32 number) |
0 | 243 |
{ |
244 |
uint32 quot,divisor; |
|
245 |
int i; |
|
246 |
uint32 tot; |
|
247 |
uint32 num; |
|
248 |
||
249 |
if (number < 0) { |
|
250 |
*buff++ = '-'; |
|
251 |
number = -number; |
|
252 |
} |
|
253 |
||
254 |
num = number; |
|
255 |
||
256 |
tot = 0; |
|
1316 | 257 |
for (i = 0; i != 10; i++) { |
0 | 258 |
divisor = _divisor_table[i]; |
259 |
quot = 0; |
|
260 |
if (num >= divisor) { |
|
261 |
quot = num / _divisor_table[i]; |
|
262 |
num = num % _divisor_table[i]; |
|
263 |
} |
|
1316 | 264 |
if (tot |= quot || i == 9) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
265 |
*buff++ = '0' + quot; |
1316 | 266 |
if (i == 0 || i == 3 || i == 6) *buff++ = ','; |
0 | 267 |
} |
268 |
} |
|
269 |
||
1316 | 270 |
*buff = '\0'; |
0 | 271 |
|
272 |
return buff; |
|
273 |
} |
|
274 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
275 |
static char *FormatNoCommaNumber(char *buff, int32 number) |
0 | 276 |
{ |
277 |
uint32 quot,divisor; |
|
278 |
int i; |
|
279 |
uint32 tot; |
|
280 |
uint32 num; |
|
281 |
||
282 |
if (number < 0) { |
|
283 |
*buff++ = '-'; |
|
284 |
number = -number; |
|
285 |
} |
|
286 |
||
287 |
num = number; |
|
288 |
||
289 |
tot = 0; |
|
1316 | 290 |
for (i = 0; i != 10; i++) { |
0 | 291 |
divisor = _divisor_table[i]; |
292 |
quot = 0; |
|
293 |
if (num >= divisor) { |
|
294 |
quot = num / _divisor_table[i]; |
|
295 |
num = num % _divisor_table[i]; |
|
296 |
} |
|
1316 | 297 |
if (tot |= quot || i == 9) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
298 |
*buff++ = '0' + quot; |
0 | 299 |
} |
300 |
} |
|
301 |
||
1316 | 302 |
*buff = '\0'; |
0 | 303 |
|
304 |
return buff; |
|
305 |
} |
|
306 |
||
307 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
308 |
static char *FormatYmdString(char *buff, uint16 number) |
0 | 309 |
{ |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
310 |
const char *src; |
0 | 311 |
YearMonthDay ymd; |
312 |
||
313 |
ConvertDayToYMD(&ymd, number); |
|
314 |
||
1316 | 315 |
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
|
316 |
|
0 | 317 |
buff[-1] = ' '; |
318 |
memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4); |
|
319 |
buff[3] = ' '; |
|
320 |
||
2639 | 321 |
return FormatNoCommaNumber(buff + 4, ymd.year + MAX_YEAR_BEGIN_REAL); |
0 | 322 |
} |
323 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
324 |
static char *FormatMonthAndYear(char *buff, uint16 number) |
0 | 325 |
{ |
326 |
const char *src; |
|
327 |
YearMonthDay ymd; |
|
328 |
||
329 |
ConvertDayToYMD(&ymd, number); |
|
330 |
||
1316 | 331 |
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
0 | 332 |
buff[-1] = ' '; |
333 |
||
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
|
334 |
return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); |
0 | 335 |
} |
336 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
337 |
static char *FormatTinyDate(char *buff, uint16 number) |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
338 |
{ |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
339 |
YearMonthDay ymd; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
340 |
|
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
341 |
ConvertDayToYMD(&ymd, number); |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
342 |
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
|
343 |
|
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
344 |
return buff; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
345 |
} |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
346 |
|
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
347 |
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact) |
0 | 348 |
{ |
349 |
const char *s; |
|
350 |
char c; |
|
351 |
char buf[40], *p; |
|
352 |
int j; |
|
353 |
||
354 |
// multiply by exchange rate |
|
355 |
number *= spec->rate; |
|
356 |
||
357 |
// convert from negative |
|
1316 | 358 |
if (number < 0) { |
359 |
*buff++ = '-'; |
|
360 |
number = -number; |
|
361 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
362 |
|
788
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
363 |
// add prefix part |
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
364 |
s = spec->prefix; |
1316 | 365 |
while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c; |
0 | 366 |
|
367 |
// for huge numbers, compact the number into k or M |
|
368 |
if (compact) { |
|
369 |
compact = 0; |
|
370 |
if (number >= 1000000000) { |
|
371 |
number = (number + 500000) / 1000000; |
|
372 |
compact = 'M'; |
|
373 |
} else if (number >= 1000000) { |
|
374 |
number = (number + 500) / 1000; |
|
375 |
compact = 'k'; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
376 |
} |
0 | 377 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
378 |
|
0 | 379 |
// convert to ascii number and add commas |
380 |
p = buf; |
|
381 |
j = 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
382 |
do { |
1316 | 383 |
if (--j == 0) { |
384 |
*p++ = spec->separator; |
|
385 |
j = 3; |
|
386 |
} |
|
0 | 387 |
*p++ = '0' + number % 10; |
388 |
} while (number /= 10); |
|
389 |
do *buff++ = *--p; while (p != buf); |
|
390 |
||
391 |
if (compact) *buff++ = compact; |
|
392 |
||
788
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
393 |
// add suffix part |
f7c5d8966d59
(svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents:
762
diff
changeset
|
394 |
s = spec->suffix; |
1316 | 395 |
while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c; |
0 | 396 |
|
397 |
return buff; |
|
398 |
} |
|
399 |
||
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
400 |
static int DeterminePluralForm(int32 n) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
401 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
402 |
// The absolute value determines plurality |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
403 |
if (n < 0) n = -n; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
404 |
|
2952 | 405 |
switch (_langpack->plural_form) { |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
406 |
// Two forms, singular used for one only |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
407 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
408 |
// Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
409 |
// Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
410 |
case 0: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
411 |
default: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
412 |
return n != 1; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
413 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
414 |
// Only one form |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
415 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
416 |
// Hungarian, Japanese, Korean, Turkish |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
417 |
case 1: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
418 |
return 0; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
419 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
420 |
// Two forms, singular used for zero and one |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
421 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
422 |
// French, Brazilian Portuguese |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
423 |
case 2: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
424 |
return n > 1; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
425 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
426 |
// Three forms, special case for zero |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
427 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
428 |
// Latvian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
429 |
case 3: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
430 |
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
|
431 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
432 |
// Three forms, special case for one and two |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
433 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
434 |
// Gaelige (Irish) |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
435 |
case 4: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
436 |
return n==1 ? 0 : n==2 ? 1 : 2; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
437 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
438 |
// 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
|
439 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
440 |
// Lithuanian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
441 |
case 5: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
442 |
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
|
443 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
444 |
// 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
|
445 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
446 |
// Croatian, Czech, Russian, Slovak, Ukrainian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
447 |
case 6: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
448 |
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
|
449 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
450 |
// 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
|
451 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
452 |
// Polish |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
453 |
case 7: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
454 |
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
|
455 |
|
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
456 |
// 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
|
457 |
// Used in: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
458 |
// Slovenian |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
459 |
case 8: |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
460 |
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
|
461 |
} |
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 |
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
|
465 |
{ |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
466 |
//<NUM> {Length of each string} {each string} |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
467 |
uint n = (byte)*b++; |
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
468 |
uint pos,i, mylen=0,mypos=0; |
2952 | 469 |
|
470 |
for (i = pos = 0; i != n; i++) { |
|
2082
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 |
|
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
483 |
typedef struct Units { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
484 |
int s_m; ///< Multiplier for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
485 |
int s_s; ///< Shift for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
486 |
StringID velocity; ///< String for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
487 |
int p_m; ///< Multiplier for power |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
488 |
int p_s; ///< Shift for power |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
489 |
StringID power; ///< String for velocity |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
490 |
int w_m; ///< Multiplier for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
491 |
int w_s; ///< Shift for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
492 |
StringID s_weight; ///< Short string for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
493 |
StringID l_weight; ///< Long string for weight |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
494 |
int v_m; ///< Multiplier for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
495 |
int v_s; ///< Shift for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
496 |
StringID s_volume; ///< Short string for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
497 |
StringID l_volume; ///< Long string for volume |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
498 |
} Units; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
499 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
500 |
static const Units units[] = { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
501 |
{ // Imperial (Original) |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
502 |
10, 4, STR_UNITS_VELOCITY_IMPERIAL, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
503 |
1, 0, STR_UNITS_POWER_IMPERIAL, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
504 |
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
505 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
506 |
}, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
507 |
{ // Metric |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
508 |
1, 0, STR_UNITS_VELOCITY_METRIC, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
509 |
1, 0, STR_UNITS_POWER_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
510 |
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
511 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
512 |
}, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
513 |
{ // SI |
3477
80c3465b38ee
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
514 |
284, 10, STR_UNITS_VELOCITY_SI, |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
515 |
764, 10, STR_UNITS_POWER_SI, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
516 |
1000, 0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
517 |
1000, 0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
518 |
}, |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
519 |
}; |
2082
52fa58482eeb
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
520 |
|
2087 | 521 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei) |
0 | 522 |
{ |
523 |
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
|
524 |
const int32 *argv_orig = argv; |
2087 | 525 |
uint modifier = 0; |
0 | 526 |
|
1316 | 527 |
while ((b = *str++) != '\0') { |
528 |
switch (b) { |
|
0 | 529 |
case 0x1: // {SETX} |
530 |
*buff++ = b; |
|
531 |
*buff++ = *str++; |
|
532 |
break; |
|
533 |
case 0x2: // {SETXY} |
|
534 |
*buff++ = b; |
|
535 |
*buff++ = *str++; |
|
536 |
*buff++ = *str++; |
|
537 |
break; |
|
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
538 |
|
0 | 539 |
case 0x81: // {STRINL} |
2966
7f382cfeb93d
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2957
diff
changeset
|
540 |
buff = GetStringWithArgs(buff, ReadLE16Unaligned(str), argv); |
0 | 541 |
str += 2; |
542 |
break; |
|
543 |
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
|
544 |
buff = FormatYmdString(buff, GetInt32(&argv)); |
0 | 545 |
break; |
546 |
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
|
547 |
buff = FormatMonthAndYear(buff, GetInt32(&argv)); |
0 | 548 |
break; |
549 |
case 0x84: {// {VELOCITY} |
|
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
550 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
551 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
552 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
553 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
554 |
modifier = 0; |
0 | 555 |
break; |
556 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
557 |
// 0x85 is used as escape character.. |
0 | 558 |
case 0x85: |
1316 | 559 |
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
|
560 |
case 0: /* {CURRCOMPACT} */ |
2468
15753a8438ba
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
561 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true); |
0 | 562 |
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
|
563 |
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
|
564 |
buff = strecpy(buff, _openttd_revision, NULL); |
0 | 565 |
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
|
566 |
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
|
567 |
// Short description of cargotypes. Layout: |
0 | 568 |
// 8-bit = cargo type |
569 |
// 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
|
570 |
StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][GetInt32(&argv)]; |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
571 |
switch (cargo_str) { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
572 |
case STR_TONS: { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
573 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
574 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
575 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
576 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
577 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
578 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
579 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
580 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
581 |
case STR_LITERS: { |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
582 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
583 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
584 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
585 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
586 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
587 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
588 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
589 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
590 |
default: |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
591 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
592 |
buff = strecpy(buff, " ", NULL); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
593 |
buff = strecpy(buff, GetStringPtr(cargo_str), NULL); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
594 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
595 |
} |
1316 | 596 |
} break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
597 |
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
|
598 |
// 64 bit compact currency-unit |
2468
15753a8438ba
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
599 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true); |
0 | 600 |
break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
601 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
602 |
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
|
603 |
// String that consumes ONE argument |
2087 | 604 |
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
|
605 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1)); |
2087 | 606 |
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
|
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 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
609 |
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
|
610 |
// String that consumes TWO arguments |
2087 | 611 |
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
|
612 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2)); |
2087 | 613 |
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
|
614 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
615 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
616 |
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
|
617 |
// String that consumes THREE arguments |
2087 | 618 |
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
|
619 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3)); |
2087 | 620 |
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
|
621 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
622 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
623 |
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
|
624 |
// String that consumes FOUR arguments |
2087 | 625 |
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
|
626 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4)); |
2087 | 627 |
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
|
628 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
629 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
630 |
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
|
631 |
// String that consumes FIVE arguments |
2087 | 632 |
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
|
633 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5)); |
2087 | 634 |
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
|
635 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
636 |
} |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
637 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
638 |
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
|
639 |
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
|
640 |
break; |
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
641 |
} |
0 | 642 |
|
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
643 |
case 11: { /* {INDUSTRY} */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
644 |
const Industry* i = GetIndustry(GetInt32(&argv)); |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
645 |
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
|
646 |
|
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
647 |
// industry not valid anymore? |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
648 |
if (i->xy == 0) break; |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
649 |
|
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
650 |
// 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
|
651 |
// 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
|
652 |
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
|
653 |
args[1] = i->type + STR_4802_COAL_MINE; |
2087 | 654 |
buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24); |
655 |
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
|
656 |
break; |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
657 |
} |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
658 |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
659 |
case 12: { // {VOLUME} |
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
660 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
661 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
662 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
663 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24); |
2087 | 664 |
modifier = 0; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
665 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
666 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
667 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
668 |
case 13: { // {G 0 Der Die Das} |
2643 | 669 |
const byte* s = (const byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
670 |
int len; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
671 |
int gender = 0; |
2639 | 672 |
if (s != NULL && s[0] == 0x87) gender = s[1]; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
673 |
str = ParseStringChoice(str, gender, buff, &len); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
674 |
buff += len; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
675 |
break; |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
676 |
} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
677 |
|
2087 | 678 |
case 14: { // {DATE_TINY} |
679 |
buff = FormatTinyDate(buff, GetInt32(&argv)); |
|
680 |
break; |
|
681 |
} |
|
682 |
||
683 |
case 15: { // {CARGO} |
|
684 |
// Layout now is: |
|
685 |
// 8bit - cargo type |
|
686 |
// 16-bit - cargo count |
|
687 |
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
|
688 |
buff = GetStringWithArgs(buff, cargo_str, argv++); |
2087 | 689 |
break; |
690 |
} |
|
691 |
||
3342
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
692 |
case 16: { // {POWER} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
693 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
694 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
695 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
696 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
697 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
698 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
699 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
700 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
701 |
case 17: { // {VOLUME_S} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
702 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
703 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
704 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
705 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
706 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
707 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
708 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
709 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
710 |
case 18: { // {WEIGHT} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
711 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
712 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
713 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
714 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
715 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
716 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
717 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
718 |
|
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
719 |
case 19: { // {WEIGHT_S} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
720 |
int32 args[1]; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
721 |
assert(_opt_ptr->units < lengthof(units)); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
722 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
723 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24); |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
724 |
modifier = 0; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
725 |
break; |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
726 |
} |
0de5e6997611
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
727 |
|
0 | 728 |
default: |
729 |
error("!invalid escape sequence in string"); |
|
730 |
} |
|
731 |
break; |
|
732 |
||
733 |
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
|
734 |
argv++; |
0 | 735 |
break; |
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
736 |
|
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
737 |
// This sets up the gender for the string. |
2087 | 738 |
// 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
|
739 |
case 0x87: // {GENDER 0} |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
740 |
str++; |
0 | 741 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
742 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
743 |
case 0x88: {// {STRING} |
2087 | 744 |
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
|
745 |
// 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
|
746 |
// 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
|
747 |
// 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
|
748 |
buff = GetStringWithArgs(buff, str, argv); |
2087 | 749 |
modifier = 0; |
0 | 750 |
break; |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
751 |
} |
0 | 752 |
|
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
753 |
case 0x8B: // {COMMA} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
754 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
755 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
756 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
757 |
case 0x8C: // Move argument pointer |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
758 |
argv = argv_orig + (byte)*str++; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
759 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
760 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
761 |
case 0x8D: { // {P} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
762 |
int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
763 |
int len; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
764 |
str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len); |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
765 |
buff += len; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
766 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
767 |
} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
768 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
769 |
case 0x8E: // {NUM} |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
770 |
buff = FormatNoCommaNumber(buff, GetInt32(&argv)); |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
771 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
772 |
|
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
773 |
case 0x8F: // {CURRENCY} |
2468
15753a8438ba
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
774 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false); |
2410
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
775 |
break; |
d1fae093e768
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
776 |
|
2087 | 777 |
case 0x99: { // {WAYPOINT} |
778 |
int32 temp[2]; |
|
779 |
Waypoint *wp = GetWaypoint(GetInt32(&argv)); |
|
780 |
StringID str; |
|
781 |
if (wp->string != STR_NULL) { |
|
782 |
str = wp->string; |
|
783 |
} else { |
|
784 |
temp[0] = wp->town_index; |
|
785 |
temp[1] = wp->town_cn + 1; |
|
786 |
str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; |
|
787 |
} |
|
788 |
buff = GetStringWithArgs(buff, str, temp); |
|
789 |
} break; |
|
0 | 790 |
|
791 |
case 0x9A: { // {STATION} |
|
2630 | 792 |
const Station* st = GetStation(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
|
793 |
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
|
794 |
|
1316 | 795 |
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
|
796 |
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
|
797 |
break; |
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
798 |
} |
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
799 |
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
|
800 |
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
|
801 |
buff = GetStringWithArgs(buff, st->string_id, temp); |
0 | 802 |
break; |
803 |
} |
|
804 |
case 0x9B: { // {TOWN} |
|
2630 | 805 |
const Town* t = GetTown(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
|
806 |
int32 temp[1]; |
2639 | 807 |
|
808 |
assert(t->xy != 0); |
|
2630 | 809 |
|
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
810 |
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
|
811 |
buff = GetStringWithArgs(buff, t->townnametype, temp); |
0 | 812 |
break; |
813 |
} |
|
814 |
||
815 |
case 0x9C: { // {CURRENCY64} |
|
2468
15753a8438ba
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
816 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false); |
0 | 817 |
break; |
818 |
} |
|
819 |
||
2087 | 820 |
case 0x9D: { // {SETCASE} |
2639 | 821 |
// This is a pseudo command, it's outputted when someone does {STRING.ack} |
2087 | 822 |
// The modifier is added to all subsequent GetStringWithArgs that accept the modifier. |
823 |
modifier = (byte)*str++ << 24; |
|
824 |
break; |
|
825 |
} |
|
826 |
||
827 |
case 0x9E: { // {Used to implement case switching} |
|
828 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
|
829 |
// Each LEN is printed using 2 bytes in big endian order. |
|
830 |
uint num = (byte)*str++; |
|
831 |
while (num) { |
|
2107
607a900aefa3
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2087
diff
changeset
|
832 |
if ((byte)str[0] == casei) { |
2087 | 833 |
// Found the case, adjust str pointer and continue |
834 |
str += 3; |
|
835 |
break; |
|
836 |
} |
|
837 |
// Otherwise skip to the next case |
|
838 |
str += 3 + (str[1] << 8) + str[2]; |
|
839 |
num--; |
|
0 | 840 |
} |
1097
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
841 |
break; |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
842 |
} |
653c846fb5d9
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
843 |
|
0 | 844 |
default: |
845 |
*buff++ = b; |
|
846 |
} |
|
847 |
} |
|
1316 | 848 |
*buff = '\0'; |
0 | 849 |
return buff; |
850 |
} |
|
851 |
||
852 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
853 |
static char *StationGetSpecialString(char *buff, int x) |
0 | 854 |
{ |
2353 | 855 |
if (x & 0x01) *buff++ = '\x94'; |
856 |
if (x & 0x02) *buff++ = '\x95'; |
|
857 |
if (x & 0x04) *buff++ = '\x96'; |
|
858 |
if (x & 0x08) *buff++ = '\x97'; |
|
859 |
if (x & 0x10) *buff++ = '\x98'; |
|
1316 | 860 |
*buff = '\0'; |
0 | 861 |
return buff; |
862 |
} |
|
863 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
864 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed) |
1316 | 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 |
_town_name_generators[ind](buff, seed); |
0 | 867 |
|
1316 | 868 |
while (*buff != '\0') buff++; |
0 | 869 |
return buff; |
870 |
} |
|
871 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
872 |
static const char* const _silly_company_names[] = { |
0 | 873 |
"Bloggs Brothers", |
874 |
"Tiny Transport Ltd.", |
|
875 |
"Express Travel", |
|
876 |
"Comfy-Coach & Co.", |
|
877 |
"Crush & Bump Ltd.", |
|
878 |
"Broken & Late Ltd.", |
|
879 |
"Sam Speedy & Son", |
|
880 |
"Supersonic Travel", |
|
881 |
"Mike's Motors", |
|
882 |
"Lightning International", |
|
883 |
"Pannik & Loozit Ltd.", |
|
884 |
"Inter-City Transport", |
|
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
885 |
"Getout & Pushit Ltd." |
0 | 886 |
}; |
887 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
888 |
static const char* const _surname_list[] = { |
0 | 889 |
"Adams", |
890 |
"Allan", |
|
891 |
"Baker", |
|
892 |
"Bigwig", |
|
893 |
"Black", |
|
894 |
"Bloggs", |
|
895 |
"Brown", |
|
896 |
"Campbell", |
|
897 |
"Gordon", |
|
898 |
"Hamilton", |
|
899 |
"Hawthorn", |
|
900 |
"Higgins", |
|
901 |
"Green", |
|
902 |
"Gribble", |
|
903 |
"Jones", |
|
904 |
"McAlpine", |
|
905 |
"MacDonald", |
|
906 |
"McIntosh", |
|
907 |
"Muir", |
|
908 |
"Murphy", |
|
909 |
"Nelson", |
|
910 |
"O'Donnell", |
|
911 |
"Parker", |
|
912 |
"Phillips", |
|
913 |
"Pilkington", |
|
914 |
"Quigley", |
|
915 |
"Sharkey", |
|
916 |
"Thomson", |
|
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
917 |
"Watkins" |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
918 |
}; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
919 |
|
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
920 |
static const char* const _silly_surname_list[] = { |
0 | 921 |
"Grumpy", |
922 |
"Dozy", |
|
923 |
"Speedy", |
|
924 |
"Nosey", |
|
925 |
"Dribble", |
|
926 |
"Mushroom", |
|
927 |
"Cabbage", |
|
928 |
"Sniffle", |
|
929 |
"Fishy", |
|
930 |
"Swindle", |
|
931 |
"Sneaky", |
|
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
932 |
"Nutkins" |
0 | 933 |
}; |
934 |
||
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
935 |
static const char _initial_name_letters[] = { |
1321 | 936 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', |
937 |
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', |
|
0 | 938 |
}; |
939 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
940 |
static char *GenAndCoName(char *buff, uint32 arg) |
0 | 941 |
{ |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
942 |
const char* const* base; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
943 |
uint num; |
0 | 944 |
|
1704
2525507adda7
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
945 |
if (_opt_ptr->landscape == LT_CANDY) { |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
946 |
base = _silly_surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
947 |
num = lengthof(_silly_surname_list); |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
948 |
} else { |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
949 |
base = _surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
950 |
num = lengthof(_surname_list); |
0 | 951 |
} |
952 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
953 |
buff = strecpy(buff, 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
|
954 |
buff = strecpy(buff, " & Co.", NULL); |
0 | 955 |
|
956 |
return buff; |
|
957 |
} |
|
958 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
959 |
static char *GenPresidentName(char *buff, uint32 x) |
0 | 960 |
{ |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
961 |
const char* const* base; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
962 |
uint num; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
963 |
uint i; |
0 | 964 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
965 |
buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8]; |
0 | 966 |
buff[1] = '.'; |
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
967 |
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
|
968 |
buff += 3; |
0 | 969 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
970 |
i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8; |
0 | 971 |
if (i < sizeof(_initial_name_letters)) { |
972 |
buff[0] = _initial_name_letters[i]; |
|
973 |
buff[1] = '.'; |
|
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
974 |
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
|
975 |
buff += 3; |
0 | 976 |
} |
977 |
||
1704
2525507adda7
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
978 |
if (_opt_ptr->landscape == LT_CANDY) { |
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
979 |
base = _silly_surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
980 |
num = lengthof(_silly_surname_list); |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
981 |
} else { |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
982 |
base = _surname_list; |
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
983 |
num = lengthof(_surname_list); |
0 | 984 |
} |
985 |
||
2650
8caa93e39375
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
986 |
buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], NULL); |
0 | 987 |
|
988 |
return buff; |
|
989 |
} |
|
990 |
||
991 |
static const char * const _song_names[] = { |
|
992 |
"Tycoon DELUXE Theme", |
|
993 |
"Easy Driver", |
|
994 |
"Little Red Diesel", |
|
995 |
"Cruise Control", |
|
996 |
"Don't Walk!", |
|
997 |
"Fell Apart On Me", |
|
998 |
"City Groove", |
|
999 |
"Funk Central", |
|
1000 |
"Stoke It", |
|
1001 |
"Road Hog", |
|
1002 |
"Aliens Ate My Railway", |
|
1003 |
"Snarl Up", |
|
1004 |
"Stroll On", |
|
1005 |
"Can't Get There From Here", |
|
1006 |
"Sawyer's Tune", |
|
1007 |
"Hold That Train!", |
|
1008 |
"Movin' On", |
|
1009 |
"Goss Groove", |
|
1010 |
"Small Town", |
|
1011 |
"Broomer's Oil Rag", |
|
1012 |
"Jammit", |
|
1013 |
"Hard Drivin'" |
|
1014 |
}; |
|
1015 |
||
2063
95259a31ceb5
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1016 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) |
0 | 1017 |
{ |
1316 | 1018 |
switch (ind) { |
1321 | 1019 |
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
|
1020 |
return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], NULL); |
0 | 1021 |
|
1321 | 1022 |
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
|
1023 |
return GenAndCoName(buff, GetInt32(&argv)); |
0 | 1024 |
|
1321 | 1025 |
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
|
1026 |
return GenPresidentName(buff, GetInt32(&argv)); |
0 | 1027 |
|
1321 | 1028 |
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
|
1029 |
return strecpy(buff, _song_names[GetInt32(&argv) - 1], NULL); |
0 | 1030 |
} |
1031 |
||
1032 |
// town name? |
|
1316 | 1033 |
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
|
1034 |
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
|
1035 |
return strecpy(buff, " Transport", NULL); |
0 | 1036 |
} |
1037 |
||
1038 |
// language name? |
|
1039 |
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
|
1040 |
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
|
1041 |
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
|
1042 |
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL); |
0 | 1043 |
} |
1044 |
||
1045 |
// resolution size? |
|
1046 |
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
|
1047 |
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
|
1048 |
return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]); |
|
1049 |
} |
|
1050 |
||
1051 |
// screenshot format name? |
|
1052 |
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { |
|
1053 |
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
|
1054 |
return strecpy(buff, GetScreenshotFormatDesc(i), NULL); |
0 | 1055 |
} |
1056 |
||
1057 |
assert(0); |
|
1058 |
return NULL; |
|
1059 |
} |
|
1060 |
||
1061 |
// remap a string ID from the old format to the new format |
|
1062 |
StringID RemapOldStringID(StringID s) |
|
1063 |
{ |
|
1321 | 1064 |
switch (s) { |
1065 |
case 0x0006: return STR_SV_EMPTY; |
|
1066 |
case 0x7000: return STR_SV_UNNAMED; |
|
1067 |
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1068 |
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1069 |
case 0x8864: return STR_SV_TRAIN_NAME; |
|
1070 |
case 0x902B: return STR_SV_ROADVEH_NAME; |
|
1071 |
case 0x9830: return STR_SV_SHIP_NAME; |
|
1072 |
case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
1073 |
||
1074 |
default: |
|
2951 | 1075 |
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) { |
1321 | 1076 |
return s - 0x300F + STR_SV_STNAME; |
2951 | 1077 |
} else { |
1321 | 1078 |
return s; |
2951 | 1079 |
} |
1321 | 1080 |
} |
0 | 1081 |
} |
1082 |
||
1316 | 1083 |
bool ReadLanguagePack(int lang_index) |
1084 |
{ |
|
0 | 1085 |
int tot_count, i; |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1086 |
LanguagePack *lang_pack; |
0 | 1087 |
size_t len; |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1088 |
char **langpack_offs; |
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1089 |
char *s; |
0 | 1090 |
|
1091 |
{ |
|
1092 |
char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
|
1093 |
lang_pack = ReadFileToMem(lang, &len, 100000); |
|
1094 |
free(lang); |
|
1095 |
} |
|
1096 |
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
|
1097 |
if (len < sizeof(LanguagePack) || |
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1098 |
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
|
1099 |
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
0 | 1100 |
free(lang_pack); |
1101 |
return false; |
|
1102 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
1103 |
|
0 | 1104 |
#if defined(TTD_BIG_ENDIAN) |
1316 | 1105 |
for (i = 0; i != 32; i++) { |
2966
7f382cfeb93d
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2957
diff
changeset
|
1106 |
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]); |
0 | 1107 |
} |
1108 |
#endif |
|
1109 |
||
1110 |
tot_count = 0; |
|
1316 | 1111 |
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
|
1112 |
uint num = lang_pack->offsets[i]; |
0 | 1113 |
_langtab_start[i] = tot_count; |
1114 |
_langtab_num[i] = num; |
|
1115 |
tot_count += num; |
|
1116 |
} |
|
1117 |
||
1118 |
// Allocate offsets |
|
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1119 |
langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
0 | 1120 |
|
1121 |
// Fill offsets |
|
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1122 |
s = lang_pack->data; |
1316 | 1123 |
for (i = 0; i != tot_count; i++) { |
1312
8defbb525d09
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1124 |
len = (byte)*s; |
1316 | 1125 |
*s++ = '\0'; // zero terminate the string before. |
1126 |
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
|
0 | 1127 |
langpack_offs[i] = s; |
1128 |
s += len; |
|
1129 |
} |
|
1130 |
||
1321 | 1131 |
free(_langpack); |
0 | 1132 |
_langpack = lang_pack; |
1133 |
||
1321 | 1134 |
free(_langpack_offs); |
0 | 1135 |
_langpack_offs = langpack_offs; |
1136 |
||
1137 |
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); |
|
1138 |
||
1139 |
_dynlang.curr = lang_index; |
|
1140 |
return true; |
|
1141 |
} |
|
1142 |
||
3329
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1143 |
/** Determine the current charset based on the environment |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1144 |
* First check some default values, after this one we passed ourselves |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1145 |
* and if none exist return the value for $LANG |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1146 |
* @param environment variable to check conditionally if default ones are not |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1147 |
* set. Pass NULL if you don't want additional checks. |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1148 |
* @return return string containing current charset, or NULL if not-determinable */ |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1149 |
const char *GetCurrentLocale(const char *param) |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1150 |
{ |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1151 |
const char *env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1152 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1153 |
env = getenv("LANGUAGE"); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1154 |
if (env != NULL) return env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1155 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1156 |
env = getenv("LC_ALL"); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1157 |
if (env != NULL) return env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1158 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1159 |
if (param != NULL) { |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1160 |
env = getenv(param); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1161 |
if (env != NULL) return env; |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1162 |
} |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1163 |
|
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1164 |
return getenv("LANG"); |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1165 |
} |
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1166 |
|
0 | 1167 |
// 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
|
1168 |
void InitializeLanguagePacks(void) |
0 | 1169 |
{ |
1170 |
DynamicLanguages *dl = &_dynlang; |
|
1321 | 1171 |
int i; |
1172 |
int n; |
|
1173 |
int m; |
|
1174 |
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
|
1175 |
int fallback; |
1319
cd302ee91e27
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1176 |
LanguagePack hdr; |
0 | 1177 |
FILE *in; |
1178 |
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
|
1179 |
|
9cf0a4b8eadb
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1180 |
char lang[] = "en"; |
3329
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1181 |
const char *env = GetCurrentLocale("LC_MESSAGES"); |
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
|
1182 |
|
3329
992d1f7cb747
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1183 |
if (env != NULL) snprintf(lang, lengthof(lang), "%.2s", env); |
0 | 1184 |
n = GetLanguageList(files, lengthof(files)); |
1185 |
||
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
|
1186 |
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
|
1187 |
fallback = 0; |
0 | 1188 |
|
1189 |
// go through the language files and make sure that they are valid. |
|
1316 | 1190 |
for (i = m = 0; i != n; i++) { |
1321 | 1191 |
int j; |
1192 |
||
0 | 1193 |
char *s = str_fmt("%s%s", _path.lang_dir, files[i]); |
1194 |
in = fopen(s, "rb"); |
|
1195 |
free(s); |
|
1316 | 1196 |
if (in == NULL || |
0 | 1197 |
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 || |
1198 |
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
|
1199 |
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
|
1200 |
free(files[i]); |
|
1201 |
continue; |
|
1202 |
} |
|
1203 |
||
1204 |
dl->ent[m].file = files[i]; |
|
1205 |
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
|
1206 |
|
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
|
1207 |
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
|
1208 |
if (strcmp(hdr.isocode, lang) == 0) def = m; |
0 | 1209 |
|
1210 |
m++; |
|
1211 |
} |
|
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
|
1212 |
if (def == -1) def = fallback; |
0 | 1213 |
|
1214 |
if (m == 0) |
|
1215 |
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
|
1216 |
|
0 | 1217 |
dl->num = m; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
1218 |
for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; |
0 | 1219 |
dl->dropdown[i] = INVALID_STRING_ID; |
1220 |
||
1316 | 1221 |
for (i = 0; i != dl->num; i++) |
1222 |
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) { |
|
0 | 1223 |
def = i; |
1224 |
break; |
|
1225 |
} |
|
1226 |
||
1227 |
if (!ReadLanguagePack(def)) |
|
1228 |
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
|
1229 |
} |