author | tron |
Thu, 31 Aug 2006 22:07:49 +0000 | |
changeset 4503 | f12995d09734 |
parent 4434 | a08cb4b5c179 |
child 4505 | abb08e94a1ea |
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" |
2291
c142846954ee
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2257
diff
changeset
|
5 |
#include "currency.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#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
|
7 |
#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
|
8 |
#include "strings.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
504
diff
changeset
|
9 |
#include "table/strings.h" |
1306
7768d8361d88
(svn r1810) Move town name generation declarations into a header of their own
tron
parents:
1102
diff
changeset
|
10 |
#include "namegen.h" |
0 | 11 |
#include "station.h" |
12 |
#include "town.h" |
|
13 |
#include "vehicle.h" |
|
6
e9b56d50aa99
(svn r7) -Feature [1003350] Euro introduction news item. (dominik81)
darkvater
parents:
0
diff
changeset
|
14 |
#include "news.h" |
430 | 15 |
#include "screenshot.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1376
diff
changeset
|
16 |
#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
|
17 |
#include "industry.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
18 |
#include "variables.h" |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
19 |
#include "newgrf_text.h" |
3616
65f9ec8fe4fb
(svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents:
3601
diff
changeset
|
20 |
#include "table/landscape_const.h" |
4120
b21fda0c260a
(svn r5464) [Behaviour Fix] : When starting the game, the system will now verify the presence of music files in gm forlder.
belugas
parents:
3833
diff
changeset
|
21 |
#include "music.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4219
diff
changeset
|
22 |
#include "date.h" |
0 | 23 |
|
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
24 |
#ifdef WIN32 |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
25 |
/* for opendir/readdir/closedir */ |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
26 |
# include "fios.h" |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
27 |
#else |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
28 |
# include <sys/types.h> |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
29 |
# include <dirent.h> |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
30 |
#endif /* WIN32 */ |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
31 |
|
2201 | 32 |
char _userstring[128]; |
33 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv); |
0 | 37 |
|
2087 | 38 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei); |
0 | 39 |
|
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
|
40 |
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
|
41 |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
42 |
typedef struct LanguagePack { |
0 | 43 |
uint32 ident; |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
44 |
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
45 |
char name[32]; // the international name of this language |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
46 |
char own_name[32]; // the localized name of this language |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
47 |
char isocode[16]; // the ISO code for the language (not country code) |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
48 |
uint16 offsets[32]; // the offsets |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
49 |
byte plural_form; // how to compute plural forms |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4416
diff
changeset
|
50 |
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
|
51 |
char data[VARARRAY_SIZE]; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
52 |
} LanguagePack; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
53 |
|
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
54 |
static char **_langpack_offs; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
55 |
static LanguagePack *_langpack; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
56 |
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
|
57 |
static uint _langtab_start[32]; // Offset into langpack offs |
0 | 58 |
|
1321 | 59 |
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = { |
1316 | 60 |
{ /* LT_NORMAL */ |
61 |
STR_PASSENGERS, |
|
62 |
STR_TONS, |
|
63 |
STR_BAGS, |
|
64 |
STR_LITERS, |
|
65 |
STR_ITEMS, |
|
66 |
STR_CRATES, |
|
67 |
STR_TONS, |
|
68 |
STR_TONS, |
|
69 |
STR_TONS, |
|
70 |
STR_TONS, |
|
71 |
STR_BAGS, |
|
72 |
STR_RES_OTHER |
|
73 |
}, |
|
74 |
||
75 |
{ /* LT_HILLY */ |
|
76 |
STR_PASSENGERS, |
|
77 |
STR_TONS, |
|
78 |
STR_BAGS, |
|
79 |
STR_LITERS, |
|
80 |
STR_ITEMS, |
|
81 |
STR_CRATES, |
|
82 |
STR_TONS, |
|
83 |
STR_TONS, |
|
84 |
STR_RES_OTHER, |
|
85 |
STR_TONS, |
|
86 |
STR_BAGS, |
|
87 |
STR_TONS |
|
88 |
}, |
|
89 |
||
90 |
{ /* LT_DESERT */ |
|
91 |
STR_PASSENGERS, |
|
92 |
STR_LITERS, |
|
93 |
STR_BAGS, |
|
94 |
STR_LITERS, |
|
95 |
STR_TONS, |
|
96 |
STR_CRATES, |
|
97 |
STR_TONS, |
|
98 |
STR_TONS, |
|
99 |
STR_TONS, |
|
100 |
STR_LITERS, |
|
101 |
STR_BAGS, |
|
102 |
STR_TONS |
|
103 |
}, |
|
104 |
||
105 |
{ /* LT_CANDY */ |
|
106 |
STR_PASSENGERS, |
|
107 |
STR_TONS, |
|
108 |
STR_BAGS, |
|
109 |
STR_NOTHING, |
|
110 |
STR_NOTHING, |
|
111 |
STR_TONS, |
|
112 |
STR_TONS, |
|
113 |
STR_LITERS, |
|
114 |
STR_TONS, |
|
115 |
STR_NOTHING, |
|
116 |
STR_LITERS, |
|
117 |
STR_NOTHING |
|
118 |
} |
|
0 | 119 |
}; |
120 |
||
121 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
122 |
// 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
|
123 |
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
|
124 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
125 |
int64 result; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
126 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
127 |
assert(argv); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
128 |
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
|
129 |
(*argv)+=2; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
130 |
return result; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
131 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
132 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
133 |
// 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
|
134 |
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
|
135 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
136 |
assert(argv); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
137 |
return *(*argv)++; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
138 |
} |
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 |
// 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
|
141 |
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
|
142 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
143 |
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
|
144 |
assert(*argv); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
145 |
result = *argv; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
146 |
(*argv) += n; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
147 |
return result; |
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 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
150 |
|
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
|
151 |
#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
|
152 |
|
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
|
153 |
// 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
|
154 |
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
|
155 |
|
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
|
156 |
// 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
|
157 |
// 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
|
158 |
// 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
|
159 |
// 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
|
160 |
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
|
161 |
|
1321 | 162 |
static const char *GetStringPtr(StringID string) |
0 | 163 |
{ |
164 |
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; |
|
165 |
} |
|
166 |
||
2087 | 167 |
// The highest 8 bits of string contain the "case index". |
168 |
// These 8 bits will only be set when FormatString wants to print |
|
169 |
// the string in a different case. No one else except FormatString |
|
4405
07dead19636c
(svn r6158) -Revert r6139 as that breaks strings with cases. Thanks michi_cc
Darkvater
parents:
4386
diff
changeset
|
170 |
// should set those bits, therefore string CANNOT be StringID, but uint32. |
4416
442b18840569
(svn r6169) -Codechange: Use GetString() instead of GetStringWithArgs() which should be
Darkvater
parents:
4405
diff
changeset
|
171 |
static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv) |
0 | 172 |
{ |
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
|
173 |
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
|
174 |
uint tab = GB(string, 11, 5); |
0 | 175 |
|
2635 | 176 |
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString"); |
0 | 177 |
|
1321 | 178 |
switch (tab) { |
179 |
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
|
180 |
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
|
181 |
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv)); |
1321 | 182 |
break; |
183 |
||
184 |
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
|
185 |
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
|
186 |
return GetSpecialPlayerNameString(buffr, index - 0xE4, argv); |
1321 | 187 |
break; |
188 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
189 |
// User defined name |
1321 | 190 |
case 15: |
191 |
return GetName(index, buffr); |
|
192 |
||
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
193 |
case 28: |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
194 |
return GetGRFString(buffr, index); |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
195 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
196 |
case 29: |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
197 |
return GetGRFString(buffr, index + 0x800); |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
198 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
199 |
case 30: |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
200 |
return GetGRFString(buffr, index + 0x1000); |
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
201 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
202 |
case 31: |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
203 |
// 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
|
204 |
// 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
|
205 |
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
|
206 |
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
|
207 |
} |
1321 | 208 |
|
2087 | 209 |
return FormatString(buffr, _userstring, NULL, 0); |
0 | 210 |
} |
211 |
||
2639 | 212 |
if (index >= _langtab_num[tab]) { |
1321 | 213 |
error( |
214 |
"!String 0x%X is invalid. " |
|
215 |
"Probably because an old version of the .lng file.\n", string |
|
216 |
); |
|
2639 | 217 |
} |
0 | 218 |
|
2635 | 219 |
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8)); |
0 | 220 |
} |
221 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
222 |
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
|
223 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
224 |
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
|
225 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
226 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
227 |
|
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
|
228 |
// 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
|
229 |
// 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
|
230 |
// 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
|
231 |
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
|
232 |
{ |
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 |
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
|
234 |
_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
|
235 |
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
|
236 |
} |
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 |
// 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
|
239 |
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
|
240 |
{ |
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 |
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
|
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 |
|
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
|
244 |
void InjectDParam(int amount) |
0 | 245 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
246 |
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); |
0 | 247 |
} |
248 |
||
249 |
static const uint32 _divisor_table[] = { |
|
250 |
1000000000, |
|
251 |
100000000, |
|
252 |
10000000, |
|
253 |
1000000, |
|
254 |
||
255 |
100000, |
|
256 |
10000, |
|
257 |
1000, |
|
258 |
100, |
|
259 |
10, |
|
260 |
1 |
|
261 |
}; |
|
262 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
263 |
static char *FormatCommaNumber(char *buff, int32 number) |
0 | 264 |
{ |
265 |
uint32 quot,divisor; |
|
266 |
int i; |
|
267 |
uint32 tot; |
|
268 |
uint32 num; |
|
269 |
||
270 |
if (number < 0) { |
|
271 |
*buff++ = '-'; |
|
272 |
number = -number; |
|
273 |
} |
|
274 |
||
275 |
num = number; |
|
276 |
||
277 |
tot = 0; |
|
1316 | 278 |
for (i = 0; i != 10; i++) { |
0 | 279 |
divisor = _divisor_table[i]; |
280 |
quot = 0; |
|
281 |
if (num >= divisor) { |
|
282 |
quot = num / _divisor_table[i]; |
|
283 |
num = num % _divisor_table[i]; |
|
284 |
} |
|
1316 | 285 |
if (tot |= quot || i == 9) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
286 |
*buff++ = '0' + quot; |
1316 | 287 |
if (i == 0 || i == 3 || i == 6) *buff++ = ','; |
0 | 288 |
} |
289 |
} |
|
290 |
||
1316 | 291 |
*buff = '\0'; |
0 | 292 |
|
293 |
return buff; |
|
294 |
} |
|
295 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
296 |
static char *FormatNoCommaNumber(char *buff, int32 number) |
0 | 297 |
{ |
298 |
uint32 quot,divisor; |
|
299 |
int i; |
|
300 |
uint32 tot; |
|
301 |
uint32 num; |
|
302 |
||
303 |
if (number < 0) { |
|
304 |
*buff++ = '-'; |
|
305 |
number = -number; |
|
306 |
} |
|
307 |
||
308 |
num = number; |
|
309 |
||
310 |
tot = 0; |
|
1316 | 311 |
for (i = 0; i != 10; i++) { |
0 | 312 |
divisor = _divisor_table[i]; |
313 |
quot = 0; |
|
314 |
if (num >= divisor) { |
|
315 |
quot = num / _divisor_table[i]; |
|
316 |
num = num % _divisor_table[i]; |
|
317 |
} |
|
1316 | 318 |
if (tot |= quot || i == 9) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
319 |
*buff++ = '0' + quot; |
0 | 320 |
} |
321 |
} |
|
322 |
||
1316 | 323 |
*buff = '\0'; |
0 | 324 |
|
325 |
return buff; |
|
326 |
} |
|
327 |
||
328 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
329 |
static char *FormatYmdString(char *buff, Date date) |
0 | 330 |
{ |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
331 |
const char *src; |
0 | 332 |
YearMonthDay ymd; |
333 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
334 |
ConvertDateToYMD(date, &ymd); |
0 | 335 |
|
1316 | 336 |
for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {} |
0 | 337 |
buff[-1] = ' '; |
3832
dd834d3220b8
(svn r4854) - Codechange: don't assume a short format month is 3 characters -- copy the string in the same way the other parts
peter1138
parents:
3616
diff
changeset
|
338 |
|
dd834d3220b8
(svn r4854) - Codechange: don't assume a short format month is 3 characters -- copy the string in the same way the other parts
peter1138
parents:
3616
diff
changeset
|
339 |
for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
dd834d3220b8
(svn r4854) - Codechange: don't assume a short format month is 3 characters -- copy the string in the same way the other parts
peter1138
parents:
3616
diff
changeset
|
340 |
buff[-1] = ' '; |
0 | 341 |
|
4293
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4289
diff
changeset
|
342 |
return FormatNoCommaNumber(buff, ymd.year); |
0 | 343 |
} |
344 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
345 |
static char *FormatMonthAndYear(char *buff, Date date) |
0 | 346 |
{ |
347 |
const char *src; |
|
348 |
YearMonthDay ymd; |
|
349 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
350 |
ConvertDateToYMD(date, &ymd); |
0 | 351 |
|
1316 | 352 |
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {} |
0 | 353 |
buff[-1] = ' '; |
354 |
||
4293
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4289
diff
changeset
|
355 |
return FormatNoCommaNumber(buff, ymd.year); |
0 | 356 |
} |
357 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
358 |
static char *FormatTinyDate(char *buff, Date date) |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
359 |
{ |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
360 |
YearMonthDay ymd; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
361 |
|
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
362 |
ConvertDateToYMD(date, &ymd); |
4293
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4289
diff
changeset
|
363 |
buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year); |
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 |
return buff; |
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 |
|
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
368 |
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact) |
0 | 369 |
{ |
370 |
const char *s; |
|
371 |
char c; |
|
372 |
char buf[40], *p; |
|
373 |
int j; |
|
374 |
||
375 |
// multiply by exchange rate |
|
376 |
number *= spec->rate; |
|
377 |
||
378 |
// convert from negative |
|
1316 | 379 |
if (number < 0) { |
380 |
*buff++ = '-'; |
|
381 |
number = -number; |
|
382 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
383 |
|
4377
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
384 |
/* add prefix part, only if it is specified by symbol_pos */ |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
385 |
if (spec->symbol_pos == 0) { |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
386 |
s = spec->prefix; |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
387 |
while (s != spec->prefix + lengthof(spec->prefix) && (c = *(s++)) != '\0') *(buff)++ = c; |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
388 |
} |
0 | 389 |
|
390 |
// for huge numbers, compact the number into k or M |
|
391 |
if (compact) { |
|
392 |
compact = 0; |
|
393 |
if (number >= 1000000000) { |
|
394 |
number = (number + 500000) / 1000000; |
|
395 |
compact = 'M'; |
|
396 |
} else if (number >= 1000000) { |
|
397 |
number = (number + 500) / 1000; |
|
398 |
compact = 'k'; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
399 |
} |
0 | 400 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
401 |
|
0 | 402 |
// convert to ascii number and add commas |
403 |
p = buf; |
|
404 |
j = 4; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
405 |
do { |
1316 | 406 |
if (--j == 0) { |
407 |
*p++ = spec->separator; |
|
408 |
j = 3; |
|
409 |
} |
|
0 | 410 |
*p++ = '0' + number % 10; |
411 |
} while (number /= 10); |
|
412 |
do *buff++ = *--p; while (p != buf); |
|
413 |
||
414 |
if (compact) *buff++ = compact; |
|
415 |
||
4377
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
416 |
/* add suffix part, only if it is specified by symbol_pos */ |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
417 |
if (spec->symbol_pos != 0) { |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
418 |
s = spec->suffix; |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
419 |
while (s != spec->suffix + lengthof(spec->suffix) && (c = *(s++)) != '\0') *(buff++) = c; |
f04bcf6f9a04
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4346
diff
changeset
|
420 |
} |
0 | 421 |
|
422 |
return buff; |
|
423 |
} |
|
424 |
||
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
425 |
static int DeterminePluralForm(int32 n) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
426 |
{ |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
427 |
// The absolute value determines plurality |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
428 |
if (n < 0) n = -n; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
429 |
|
2952 | 430 |
switch (_langpack->plural_form) { |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
431 |
// Two forms, singular used for one only |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
432 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
433 |
// Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
434 |
// Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
435 |
case 0: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
436 |
default: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
437 |
return n != 1; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
438 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
439 |
// Only one form |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
440 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
441 |
// Hungarian, Japanese, Korean, Turkish |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
442 |
case 1: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
443 |
return 0; |
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 |
// Two forms, singular used for zero and one |
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 |
// French, Brazilian Portuguese |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
448 |
case 2: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
449 |
return n > 1; |
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 |
// Three forms, special case for zero |
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 |
// Latvian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
454 |
case 3: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
455 |
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
|
456 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
457 |
// Three forms, special case for one and two |
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 |
// Gaelige (Irish) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
460 |
case 4: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
461 |
return n==1 ? 0 : n==2 ? 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 numbers ending in 1[2-9] |
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 |
// Lithuanian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
466 |
case 5: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
467 |
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
|
468 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
469 |
// 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
|
470 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
471 |
// Croatian, Czech, Russian, Slovak, Ukrainian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
472 |
case 6: |
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%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
|
474 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
475 |
// 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
|
476 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
477 |
// Polish |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
478 |
case 7: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
479 |
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
|
480 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
481 |
// 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
|
482 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
483 |
// Slovenian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
484 |
case 8: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
485 |
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
|
486 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
487 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
488 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
489 |
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
|
490 |
{ |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
491 |
//<NUM> {Length of each string} {each string} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
492 |
uint n = (byte)*b++; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
493 |
uint pos,i, mylen=0,mypos=0; |
2952 | 494 |
|
495 |
for (i = pos = 0; i != n; i++) { |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
496 |
uint len = (byte)*b++; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
497 |
if (i == form) { |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
498 |
mypos = pos; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
499 |
mylen = len; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
500 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
501 |
pos += len; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
502 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
503 |
*dstlen = mylen; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
504 |
memcpy(dst, b + mypos, mylen); |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
505 |
return b + pos; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
506 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
507 |
|
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
508 |
typedef struct Units { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
509 |
int s_m; ///< Multiplier for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
510 |
int s_s; ///< Shift for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
511 |
StringID velocity; ///< String for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
512 |
int p_m; ///< Multiplier for power |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
513 |
int p_s; ///< Shift for power |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
514 |
StringID power; ///< String for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
515 |
int w_m; ///< Multiplier for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
516 |
int w_s; ///< Shift for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
517 |
StringID s_weight; ///< Short string for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
518 |
StringID l_weight; ///< Long string for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
519 |
int v_m; ///< Multiplier for volume |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
520 |
int v_s; ///< Shift for volume |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
521 |
StringID s_volume; ///< Short string for volume |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
522 |
StringID l_volume; ///< Long string for volume |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
523 |
int f_m; ///< Multiplier for force |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
524 |
int f_s; ///< Shift for force |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
525 |
StringID force; ///< String for force |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
526 |
} Units; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
527 |
|
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
528 |
/* Unit conversions */ |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
529 |
static const Units units[] = { |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
530 |
{ // Imperial (Original, mph, hp, metric ton, litre, metric ton force) |
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
531 |
10, 4, STR_UNITS_VELOCITY_IMPERIAL, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
532 |
1, 0, STR_UNITS_POWER_IMPERIAL, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
533 |
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
534 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
535 |
835, 13, STR_UNITS_FORCE_METRIC, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
536 |
}, |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
537 |
{ // Metric (km/h, hp, metric ton, litre, metric ton force) |
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
538 |
1, 0, STR_UNITS_VELOCITY_METRIC, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
539 |
1, 0, STR_UNITS_POWER_METRIC, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
540 |
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
541 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
542 |
835, 13, STR_UNITS_FORCE_METRIC, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
543 |
}, |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
544 |
{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton) |
3477
4a686a43af8a
(svn r4322) - Codechange: Remove conversion of kmh to mph from gui code to within the units conversion system, in string.c. This means displaying kmh requires no conversion, instead of being convert from kmh to mph, and then back to kmh again.
peter1138
parents:
3342
diff
changeset
|
545 |
284, 10, STR_UNITS_VELOCITY_SI, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
546 |
764, 10, STR_UNITS_POWER_SI, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
547 |
1000, 0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, |
3485
1c77f46830c9
(svn r4336) Fix units conversion of volume for SI
peter1138
parents:
3477
diff
changeset
|
548 |
1, 0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
549 |
1, 0, STR_UNITS_FORCE_SI, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
550 |
}, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
551 |
}; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
552 |
|
2087 | 553 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei) |
0 | 554 |
{ |
555 |
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
|
556 |
const int32 *argv_orig = argv; |
2087 | 557 |
uint modifier = 0; |
0 | 558 |
|
1316 | 559 |
while ((b = *str++) != '\0') { |
560 |
switch (b) { |
|
0 | 561 |
case 0x1: // {SETX} |
562 |
*buff++ = b; |
|
563 |
*buff++ = *str++; |
|
564 |
break; |
|
565 |
case 0x2: // {SETXY} |
|
566 |
*buff++ = b; |
|
567 |
*buff++ = *str++; |
|
568 |
*buff++ = *str++; |
|
569 |
break; |
|
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
570 |
|
0 | 571 |
case 0x81: // {STRINL} |
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2957
diff
changeset
|
572 |
buff = GetStringWithArgs(buff, ReadLE16Unaligned(str), argv); |
0 | 573 |
str += 2; |
574 |
break; |
|
575 |
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
|
576 |
buff = FormatYmdString(buff, GetInt32(&argv)); |
0 | 577 |
break; |
578 |
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
|
579 |
buff = FormatMonthAndYear(buff, GetInt32(&argv)); |
0 | 580 |
break; |
581 |
case 0x84: {// {VELOCITY} |
|
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
582 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
583 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
584 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
585 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
586 |
modifier = 0; |
0 | 587 |
break; |
588 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
589 |
// 0x85 is used as escape character.. |
0 | 590 |
case 0x85: |
1316 | 591 |
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
|
592 |
case 0: /* {CURRCOMPACT} */ |
2468
9ea52370a093
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
593 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true); |
0 | 594 |
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
|
595 |
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
|
596 |
buff = strecpy(buff, _openttd_revision, NULL); |
0 | 597 |
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
|
598 |
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
|
599 |
// Short description of cargotypes. Layout: |
0 | 600 |
// 8-bit = cargo type |
601 |
// 16-bit = cargo count |
|
3616
65f9ec8fe4fb
(svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents:
3601
diff
changeset
|
602 |
StringID cargo_str = _cargo_types_base_values[_opt_ptr->landscape].units_volume[GetInt32(&argv)]; |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
603 |
switch (cargo_str) { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
604 |
case STR_TONS: { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
605 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
606 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
607 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
608 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
609 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
610 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
611 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
612 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
613 |
case STR_LITERS: { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
614 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
615 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
616 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
617 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
618 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
619 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
620 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
621 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
622 |
default: |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
623 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
624 |
buff = strecpy(buff, " ", NULL); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
625 |
buff = strecpy(buff, GetStringPtr(cargo_str), NULL); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
626 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
627 |
} |
1316 | 628 |
} break; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
629 |
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
|
630 |
// 64 bit compact currency-unit |
2468
9ea52370a093
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
631 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true); |
0 | 632 |
break; |
2063
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 |
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
|
635 |
// String that consumes ONE argument |
2087 | 636 |
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
|
637 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1)); |
2087 | 638 |
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
|
639 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
640 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
641 |
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
|
642 |
// String that consumes TWO arguments |
2087 | 643 |
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
|
644 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2)); |
2087 | 645 |
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
|
646 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
647 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
648 |
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
|
649 |
// String that consumes THREE arguments |
2087 | 650 |
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
|
651 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3)); |
2087 | 652 |
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
|
653 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
654 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
655 |
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
|
656 |
// String that consumes FOUR arguments |
2087 | 657 |
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
|
658 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4)); |
2087 | 659 |
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
|
660 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
661 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
662 |
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
|
663 |
// String that consumes FIVE arguments |
2087 | 664 |
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
|
665 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5)); |
2087 | 666 |
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
|
667 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
668 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
669 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
670 |
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
|
671 |
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
|
672 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
673 |
} |
0 | 674 |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
675 |
case 11: { /* {INDUSTRY} */ |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
676 |
const Industry* i = GetIndustry(GetInt32(&argv)); |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
677 |
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
|
678 |
|
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
679 |
// industry not valid anymore? |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4321
diff
changeset
|
680 |
if (!IsValidIndustry(i)) break; |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
681 |
|
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
682 |
// 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
|
683 |
// 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
|
684 |
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
|
685 |
args[1] = i->type + STR_4802_COAL_MINE; |
2087 | 686 |
buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24); |
687 |
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
|
688 |
break; |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
689 |
} |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
690 |
|
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
691 |
case 12: { // {VOLUME} |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
692 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
693 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
694 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
695 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24); |
2087 | 696 |
modifier = 0; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
697 |
break; |
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 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
700 |
case 13: { // {G 0 Der Die Das} |
2643 | 701 |
const byte* s = (const byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
702 |
int len; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
703 |
int gender = 0; |
2639 | 704 |
if (s != NULL && s[0] == 0x87) gender = s[1]; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
705 |
str = ParseStringChoice(str, gender, buff, &len); |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
706 |
buff += len; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
707 |
break; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
708 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
709 |
|
2087 | 710 |
case 14: { // {DATE_TINY} |
711 |
buff = FormatTinyDate(buff, GetInt32(&argv)); |
|
712 |
break; |
|
713 |
} |
|
714 |
||
715 |
case 15: { // {CARGO} |
|
716 |
// Layout now is: |
|
717 |
// 8bit - cargo type |
|
718 |
// 16-bit - cargo count |
|
719 |
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
|
720 |
buff = GetStringWithArgs(buff, cargo_str, argv++); |
2087 | 721 |
break; |
722 |
} |
|
723 |
||
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
724 |
case 16: { // {POWER} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
725 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
726 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
727 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
728 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
729 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
730 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
731 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
732 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
733 |
case 17: { // {VOLUME_S} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
734 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
735 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
736 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
737 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
738 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
739 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
740 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
741 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
742 |
case 18: { // {WEIGHT} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
743 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
744 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
745 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
746 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
747 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
748 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
749 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
750 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
751 |
case 19: { // {WEIGHT_S} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
752 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
753 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
754 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
755 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
756 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
757 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
758 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
759 |
|
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
760 |
case 20: { // {FORCE} |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
761 |
int32 args[1]; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
762 |
assert(_opt_ptr->units < lengthof(units)); |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
763 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
764 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24); |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
765 |
modifier = 0; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
766 |
break; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
767 |
} |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
768 |
|
0 | 769 |
default: |
770 |
error("!invalid escape sequence in string"); |
|
771 |
} |
|
772 |
break; |
|
773 |
||
774 |
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
|
775 |
argv++; |
0 | 776 |
break; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
777 |
|
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
778 |
// This sets up the gender for the string. |
2087 | 779 |
// 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
|
780 |
case 0x87: // {GENDER 0} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
781 |
str++; |
0 | 782 |
break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
783 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
784 |
case 0x88: {// {STRING} |
2087 | 785 |
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
|
786 |
// 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
|
787 |
// 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
|
788 |
// 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
|
789 |
buff = GetStringWithArgs(buff, str, argv); |
2087 | 790 |
modifier = 0; |
0 | 791 |
break; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
792 |
} |
0 | 793 |
|
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
794 |
case 0x8B: // {COMMA} |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
795 |
buff = FormatCommaNumber(buff, GetInt32(&argv)); |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
796 |
break; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
797 |
|
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
798 |
case 0x8C: // Move argument pointer |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
799 |
argv = argv_orig + (byte)*str++; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
800 |
break; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
801 |
|
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
802 |
case 0x8D: { // {P} |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
803 |
int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
804 |
int len; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
805 |
str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len); |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
806 |
buff += len; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
807 |
break; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
808 |
} |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
809 |
|
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
810 |
case 0x8E: // {NUM} |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
811 |
buff = FormatNoCommaNumber(buff, GetInt32(&argv)); |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
812 |
break; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
813 |
|
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
814 |
case 0x8F: // {CURRENCY} |
2468
9ea52370a093
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
815 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false); |
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
816 |
break; |
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
817 |
|
2087 | 818 |
case 0x99: { // {WAYPOINT} |
819 |
int32 temp[2]; |
|
820 |
Waypoint *wp = GetWaypoint(GetInt32(&argv)); |
|
821 |
StringID str; |
|
822 |
if (wp->string != STR_NULL) { |
|
823 |
str = wp->string; |
|
824 |
} else { |
|
825 |
temp[0] = wp->town_index; |
|
826 |
temp[1] = wp->town_cn + 1; |
|
827 |
str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; |
|
828 |
} |
|
829 |
buff = GetStringWithArgs(buff, str, temp); |
|
830 |
} break; |
|
0 | 831 |
|
832 |
case 0x9A: { // {STATION} |
|
2630 | 833 |
const Station* st = GetStation(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
|
834 |
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
|
835 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4321
diff
changeset
|
836 |
if (!IsValidStation(st)) { // 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
|
837 |
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
|
838 |
break; |
93656f16d50a
(svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents:
26
diff
changeset
|
839 |
} |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
840 |
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
|
841 |
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
|
842 |
buff = GetStringWithArgs(buff, st->string_id, temp); |
0 | 843 |
break; |
844 |
} |
|
845 |
case 0x9B: { // {TOWN} |
|
2630 | 846 |
const Town* t = GetTown(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
|
847 |
int32 temp[1]; |
2639 | 848 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4321
diff
changeset
|
849 |
assert(IsValidTown(t)); |
2630 | 850 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
851 |
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
|
852 |
buff = GetStringWithArgs(buff, t->townnametype, temp); |
0 | 853 |
break; |
854 |
} |
|
855 |
||
856 |
case 0x9C: { // {CURRENCY64} |
|
2468
9ea52370a093
(svn r2994) Another small hack regarding currencies: add a #define to emulate a variable, that holds the current currency; again this should increase readability
tron
parents:
2410
diff
changeset
|
857 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false); |
0 | 858 |
break; |
859 |
} |
|
860 |
||
2087 | 861 |
case 0x9D: { // {SETCASE} |
2639 | 862 |
// This is a pseudo command, it's outputted when someone does {STRING.ack} |
2087 | 863 |
// The modifier is added to all subsequent GetStringWithArgs that accept the modifier. |
864 |
modifier = (byte)*str++ << 24; |
|
865 |
break; |
|
866 |
} |
|
867 |
||
868 |
case 0x9E: { // {Used to implement case switching} |
|
869 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
|
870 |
// Each LEN is printed using 2 bytes in big endian order. |
|
871 |
uint num = (byte)*str++; |
|
872 |
while (num) { |
|
2107
c7eb140bf9bb
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2087
diff
changeset
|
873 |
if ((byte)str[0] == casei) { |
2087 | 874 |
// Found the case, adjust str pointer and continue |
875 |
str += 3; |
|
876 |
break; |
|
877 |
} |
|
878 |
// Otherwise skip to the next case |
|
879 |
str += 3 + (str[1] << 8) + str[2]; |
|
880 |
num--; |
|
0 | 881 |
} |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
882 |
break; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
883 |
} |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
884 |
|
0 | 885 |
default: |
886 |
*buff++ = b; |
|
887 |
} |
|
888 |
} |
|
1316 | 889 |
*buff = '\0'; |
0 | 890 |
return buff; |
891 |
} |
|
892 |
||
893 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
894 |
static char *StationGetSpecialString(char *buff, int x) |
0 | 895 |
{ |
2353 | 896 |
if (x & 0x01) *buff++ = '\x94'; |
897 |
if (x & 0x02) *buff++ = '\x95'; |
|
898 |
if (x & 0x04) *buff++ = '\x96'; |
|
899 |
if (x & 0x08) *buff++ = '\x97'; |
|
900 |
if (x & 0x10) *buff++ = '\x98'; |
|
1316 | 901 |
*buff = '\0'; |
0 | 902 |
return buff; |
903 |
} |
|
904 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
905 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed) |
1316 | 906 |
{ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
907 |
_town_name_generators[ind](buff, seed); |
0 | 908 |
|
1316 | 909 |
while (*buff != '\0') buff++; |
0 | 910 |
return buff; |
911 |
} |
|
912 |
||
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
913 |
static const char* const _silly_company_names[] = { |
0 | 914 |
"Bloggs Brothers", |
915 |
"Tiny Transport Ltd.", |
|
916 |
"Express Travel", |
|
917 |
"Comfy-Coach & Co.", |
|
918 |
"Crush & Bump Ltd.", |
|
919 |
"Broken & Late Ltd.", |
|
920 |
"Sam Speedy & Son", |
|
921 |
"Supersonic Travel", |
|
922 |
"Mike's Motors", |
|
923 |
"Lightning International", |
|
924 |
"Pannik & Loozit Ltd.", |
|
925 |
"Inter-City Transport", |
|
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
926 |
"Getout & Pushit Ltd." |
0 | 927 |
}; |
928 |
||
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
929 |
static const char* const _surname_list[] = { |
0 | 930 |
"Adams", |
931 |
"Allan", |
|
932 |
"Baker", |
|
933 |
"Bigwig", |
|
934 |
"Black", |
|
935 |
"Bloggs", |
|
936 |
"Brown", |
|
937 |
"Campbell", |
|
938 |
"Gordon", |
|
939 |
"Hamilton", |
|
940 |
"Hawthorn", |
|
941 |
"Higgins", |
|
942 |
"Green", |
|
943 |
"Gribble", |
|
944 |
"Jones", |
|
945 |
"McAlpine", |
|
946 |
"MacDonald", |
|
947 |
"McIntosh", |
|
948 |
"Muir", |
|
949 |
"Murphy", |
|
950 |
"Nelson", |
|
951 |
"O'Donnell", |
|
952 |
"Parker", |
|
953 |
"Phillips", |
|
954 |
"Pilkington", |
|
955 |
"Quigley", |
|
956 |
"Sharkey", |
|
957 |
"Thomson", |
|
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
958 |
"Watkins" |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
959 |
}; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
960 |
|
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
961 |
static const char* const _silly_surname_list[] = { |
0 | 962 |
"Grumpy", |
963 |
"Dozy", |
|
964 |
"Speedy", |
|
965 |
"Nosey", |
|
966 |
"Dribble", |
|
967 |
"Mushroom", |
|
968 |
"Cabbage", |
|
969 |
"Sniffle", |
|
970 |
"Fishy", |
|
971 |
"Swindle", |
|
972 |
"Sneaky", |
|
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
973 |
"Nutkins" |
0 | 974 |
}; |
975 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
976 |
static const char _initial_name_letters[] = { |
1321 | 977 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', |
978 |
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', |
|
0 | 979 |
}; |
980 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
981 |
static char *GenAndCoName(char *buff, uint32 arg) |
0 | 982 |
{ |
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
983 |
const char* const* base; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
984 |
uint num; |
0 | 985 |
|
1704
6054160187df
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
986 |
if (_opt_ptr->landscape == LT_CANDY) { |
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
987 |
base = _silly_surname_list; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
988 |
num = lengthof(_silly_surname_list); |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
989 |
} else { |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
990 |
base = _surname_list; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
991 |
num = lengthof(_surname_list); |
0 | 992 |
} |
993 |
||
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
994 |
buff = strecpy(buff, 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
|
995 |
buff = strecpy(buff, " & Co.", NULL); |
0 | 996 |
|
997 |
return buff; |
|
998 |
} |
|
999 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1000 |
static char *GenPresidentName(char *buff, uint32 x) |
0 | 1001 |
{ |
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1002 |
const char* const* base; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1003 |
uint num; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1004 |
uint i; |
0 | 1005 |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1006 |
buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8]; |
0 | 1007 |
buff[1] = '.'; |
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
1008 |
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
|
1009 |
buff += 3; |
0 | 1010 |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
1011 |
i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8; |
0 | 1012 |
if (i < sizeof(_initial_name_letters)) { |
1013 |
buff[0] = _initial_name_letters[i]; |
|
1014 |
buff[1] = '.'; |
|
233
dd177a8c9f19
(svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents:
193
diff
changeset
|
1015 |
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
|
1016 |
buff += 3; |
0 | 1017 |
} |
1018 |
||
1704
6054160187df
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
1019 |
if (_opt_ptr->landscape == LT_CANDY) { |
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1020 |
base = _silly_surname_list; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1021 |
num = lengthof(_silly_surname_list); |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1022 |
} else { |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1023 |
base = _surname_list; |
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1024 |
num = lengthof(_surname_list); |
0 | 1025 |
} |
1026 |
||
2650
cec7c95d039d
(svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents:
2643
diff
changeset
|
1027 |
buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], NULL); |
0 | 1028 |
|
1029 |
return buff; |
|
1030 |
} |
|
1031 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
1032 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv) |
0 | 1033 |
{ |
1316 | 1034 |
switch (ind) { |
1321 | 1035 |
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
|
1036 |
return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], NULL); |
0 | 1037 |
|
1321 | 1038 |
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
|
1039 |
return GenAndCoName(buff, GetInt32(&argv)); |
0 | 1040 |
|
1321 | 1041 |
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
|
1042 |
return GenPresidentName(buff, GetInt32(&argv)); |
0 | 1043 |
|
1321 | 1044 |
case 4: // song names |
4120
b21fda0c260a
(svn r5464) [Behaviour Fix] : When starting the game, the system will now verify the presence of music files in gm forlder.
belugas
parents:
3833
diff
changeset
|
1045 |
return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, NULL); |
0 | 1046 |
} |
1047 |
||
1048 |
// town name? |
|
1316 | 1049 |
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
|
1050 |
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
|
1051 |
return strecpy(buff, " Transport", NULL); |
0 | 1052 |
} |
1053 |
||
1054 |
// language name? |
|
1055 |
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
|
1056 |
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
|
1057 |
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
|
1058 |
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL); |
0 | 1059 |
} |
1060 |
||
1061 |
// resolution size? |
|
1062 |
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
|
1063 |
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
|
1064 |
return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]); |
|
1065 |
} |
|
1066 |
||
1067 |
// screenshot format name? |
|
1068 |
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { |
|
1069 |
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
|
1070 |
return strecpy(buff, GetScreenshotFormatDesc(i), NULL); |
0 | 1071 |
} |
1072 |
||
1073 |
assert(0); |
|
1074 |
return NULL; |
|
1075 |
} |
|
1076 |
||
1077 |
// remap a string ID from the old format to the new format |
|
1078 |
StringID RemapOldStringID(StringID s) |
|
1079 |
{ |
|
1321 | 1080 |
switch (s) { |
1081 |
case 0x0006: return STR_SV_EMPTY; |
|
1082 |
case 0x7000: return STR_SV_UNNAMED; |
|
1083 |
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1084 |
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1085 |
case 0x8864: return STR_SV_TRAIN_NAME; |
|
1086 |
case 0x902B: return STR_SV_ROADVEH_NAME; |
|
1087 |
case 0x9830: return STR_SV_SHIP_NAME; |
|
1088 |
case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
1089 |
||
1090 |
default: |
|
2951 | 1091 |
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) { |
1321 | 1092 |
return s - 0x300F + STR_SV_STNAME; |
2951 | 1093 |
} else { |
1321 | 1094 |
return s; |
2951 | 1095 |
} |
1321 | 1096 |
} |
0 | 1097 |
} |
1098 |
||
1316 | 1099 |
bool ReadLanguagePack(int lang_index) |
1100 |
{ |
|
0 | 1101 |
int tot_count, i; |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1102 |
LanguagePack *lang_pack; |
0 | 1103 |
size_t len; |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1104 |
char **langpack_offs; |
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1105 |
char *s; |
0 | 1106 |
|
1107 |
{ |
|
1108 |
char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file); |
|
1109 |
lang_pack = ReadFileToMem(lang, &len, 100000); |
|
1110 |
free(lang); |
|
1111 |
} |
|
1112 |
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
|
1113 |
if (len < sizeof(LanguagePack) || |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1114 |
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
|
1115 |
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
0 | 1116 |
free(lang_pack); |
1117 |
return false; |
|
1118 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
1119 |
|
0 | 1120 |
#if defined(TTD_BIG_ENDIAN) |
1316 | 1121 |
for (i = 0; i != 32; i++) { |
2966
661554d683cd
(svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents:
2957
diff
changeset
|
1122 |
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]); |
0 | 1123 |
} |
1124 |
#endif |
|
1125 |
||
1126 |
tot_count = 0; |
|
1316 | 1127 |
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
|
1128 |
uint num = lang_pack->offsets[i]; |
0 | 1129 |
_langtab_start[i] = tot_count; |
1130 |
_langtab_num[i] = num; |
|
1131 |
tot_count += num; |
|
1132 |
} |
|
1133 |
||
1134 |
// Allocate offsets |
|
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1135 |
langpack_offs = malloc(tot_count * sizeof(*langpack_offs)); |
0 | 1136 |
|
1137 |
// Fill offsets |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1138 |
s = lang_pack->data; |
1316 | 1139 |
for (i = 0; i != tot_count; i++) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1140 |
len = (byte)*s; |
1316 | 1141 |
*s++ = '\0'; // zero terminate the string before. |
1142 |
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
|
0 | 1143 |
langpack_offs[i] = s; |
1144 |
s += len; |
|
1145 |
} |
|
1146 |
||
1321 | 1147 |
free(_langpack); |
0 | 1148 |
_langpack = lang_pack; |
1149 |
||
1321 | 1150 |
free(_langpack_offs); |
0 | 1151 |
_langpack_offs = langpack_offs; |
1152 |
||
1153 |
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); |
|
1154 |
||
1155 |
_dynlang.curr = lang_index; |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
1156 |
SetCurrentGrfLangID(_langpack->isocode); |
0 | 1157 |
return true; |
1158 |
} |
|
1159 |
||
3329
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1160 |
/** Determine the current charset based on the environment |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1161 |
* First check some default values, after this one we passed ourselves |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1162 |
* and if none exist return the value for $LANG |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1163 |
* @param environment variable to check conditionally if default ones are not |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1164 |
* set. Pass NULL if you don't want additional checks. |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1165 |
* @return return string containing current charset, or NULL if not-determinable */ |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1166 |
const char *GetCurrentLocale(const char *param) |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1167 |
{ |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1168 |
const char *env; |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1169 |
|
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1170 |
env = getenv("LANGUAGE"); |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1171 |
if (env != NULL) return env; |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1172 |
|
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1173 |
env = getenv("LC_ALL"); |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1174 |
if (env != NULL) return env; |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1175 |
|
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1176 |
if (param != NULL) { |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1177 |
env = getenv(param); |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1178 |
if (env != NULL) return env; |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1179 |
} |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1180 |
|
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1181 |
return getenv("LANG"); |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1182 |
} |
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1183 |
|
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1184 |
static int CDECL LanguageCompareFunc(const void *a, const void *b) |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1185 |
{ |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1186 |
return strcmp(*(const char* const *)a, *(const char* const *)b); |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1187 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1188 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1189 |
static int GetLanguageList(char **languages, int max) |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1190 |
{ |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1191 |
DIR *dir; |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1192 |
struct dirent *dirent; |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1193 |
int num = 0; |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1194 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1195 |
dir = opendir(_path.lang_dir); |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1196 |
if (dir != NULL) { |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1197 |
while ((dirent = readdir(dir)) != NULL) { |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1198 |
char *t = strrchr(dirent->d_name, '.'); |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1199 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1200 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1201 |
languages[num++] = strdup(dirent->d_name); |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1202 |
if (num == max) break; |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1203 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1204 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1205 |
closedir(dir); |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1206 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1207 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1208 |
qsort(languages, num, sizeof(char*), LanguageCompareFunc); |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1209 |
return num; |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1210 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1211 |
|
0 | 1212 |
// 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
|
1213 |
void InitializeLanguagePacks(void) |
0 | 1214 |
{ |
1215 |
DynamicLanguages *dl = &_dynlang; |
|
1321 | 1216 |
int i; |
1217 |
int n; |
|
1218 |
int m; |
|
1219 |
int def; |
|
2257
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1220 |
int fallback; |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1221 |
LanguagePack hdr; |
0 | 1222 |
FILE *in; |
1223 |
char *files[32]; |
|
2257
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1224 |
|
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1225 |
char lang[] = "en"; |
3329
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1226 |
const char *env = GetCurrentLocale("LC_MESSAGES"); |
2257
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1227 |
|
3329
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3033
diff
changeset
|
1228 |
if (env != NULL) snprintf(lang, lengthof(lang), "%.2s", env); |
0 | 1229 |
n = GetLanguageList(files, lengthof(files)); |
1230 |
||
2257
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1231 |
def = -1; |
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1232 |
fallback = 0; |
0 | 1233 |
|
1234 |
// go through the language files and make sure that they are valid. |
|
1316 | 1235 |
for (i = m = 0; i != n; i++) { |
4321
958a8e9c012b
(svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents:
4293
diff
changeset
|
1236 |
size_t j; |
1321 | 1237 |
|
0 | 1238 |
char *s = str_fmt("%s%s", _path.lang_dir, files[i]); |
1239 |
in = fopen(s, "rb"); |
|
1240 |
free(s); |
|
1316 | 1241 |
if (in == NULL || |
0 | 1242 |
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 || |
1243 |
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
|
1244 |
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
|
1245 |
free(files[i]); |
|
1246 |
continue; |
|
1247 |
} |
|
1248 |
||
1249 |
dl->ent[m].file = files[i]; |
|
1250 |
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
|
1251 |
|
2257
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1252 |
if (strcmp(hdr.name, "English") == 0) fallback = m; |
4503
f12995d09734
(svn r6288) -Regression: Restore automatic language detection, which was broken in r4886 when the language codes got extended
tron
parents:
4434
diff
changeset
|
1253 |
if (strncmp(hdr.isocode, lang, 2) == 0) def = m; |
0 | 1254 |
|
1255 |
m++; |
|
1256 |
} |
|
2257
ea9008cb49ec
(svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents:
2201
diff
changeset
|
1257 |
if (def == -1) def = fallback; |
0 | 1258 |
|
1259 |
if (m == 0) |
|
1260 |
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
|
1261 |
|
0 | 1262 |
dl->num = m; |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
1263 |
for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; |
0 | 1264 |
dl->dropdown[i] = INVALID_STRING_ID; |
1265 |
||
1316 | 1266 |
for (i = 0; i != dl->num; i++) |
1267 |
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) { |
|
0 | 1268 |
def = i; |
1269 |
break; |
|
1270 |
} |
|
1271 |
||
1272 |
if (!ReadLanguagePack(def)) |
|
1273 |
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
|
1274 |
} |