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