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