author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5874 | 2db89a640b7a |
child 5996 | 4bcab9c286d8 |
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" |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
21 |
#include "table/control_codes.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
|
22 |
#include "music.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4219
diff
changeset
|
23 |
#include "date.h" |
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4920
diff
changeset
|
24 |
#include "industry.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
25 |
#include "helpers.hpp" |
0 | 26 |
|
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
27 |
#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
|
28 |
/* 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
|
29 |
# 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
|
30 |
#else |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
31 |
# 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
|
32 |
# 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
|
33 |
#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
|
34 |
|
2201 | 35 |
char _userstring[128]; |
36 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
37 |
static char *StationGetSpecialString(char *buff, int x, const char* last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
38 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
39 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last); |
0 | 40 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
41 |
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei, const char* last); |
0 | 42 |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
43 |
typedef struct LanguagePack { |
0 | 44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
char data[VARARRAY_SIZE]; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
53 |
} LanguagePack; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
54 |
|
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
55 |
static char **_langpack_offs; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
56 |
static LanguagePack *_langpack; |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
57 |
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
|
58 |
static uint _langtab_start[32]; // Offset into langpack offs |
0 | 59 |
|
60 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
61 |
// 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
|
62 |
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
|
63 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
64 |
int64 result; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
65 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
66 |
assert(argv); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
67 |
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
|
68 |
(*argv)+=2; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
69 |
return result; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
70 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
71 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
72 |
// 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
|
73 |
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
|
74 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
75 |
assert(argv); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
76 |
return *(*argv)++; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
77 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
78 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
79 |
// 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
|
80 |
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
|
81 |
{ |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
82 |
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
|
83 |
assert(*argv); |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
84 |
result = *argv; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
85 |
(*argv) += n; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
86 |
return result; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
87 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
88 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
89 |
|
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
|
90 |
#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
|
91 |
|
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
|
92 |
// 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
|
93 |
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
|
94 |
|
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
|
95 |
// 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
|
96 |
// 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
|
97 |
// 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
|
98 |
// 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
|
99 |
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
|
100 |
|
1321 | 101 |
static const char *GetStringPtr(StringID string) |
0 | 102 |
{ |
103 |
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)]; |
|
104 |
} |
|
105 |
||
2087 | 106 |
// The highest 8 bits of string contain the "case index". |
107 |
// These 8 bits will only be set when FormatString wants to print |
|
108 |
// 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
|
109 |
// should set those bits, therefore string CANNOT be StringID, but uint32. |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
110 |
static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv, const char* last) |
0 | 111 |
{ |
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
|
112 |
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
|
113 |
uint tab = GB(string, 11, 5); |
4710
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
114 |
char buff[512]; |
0 | 115 |
|
2635 | 116 |
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString"); |
0 | 117 |
|
1321 | 118 |
switch (tab) { |
119 |
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
|
120 |
if (index >= 0xC0) |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
121 |
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv), last); |
1321 | 122 |
break; |
123 |
||
124 |
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
|
125 |
if (index >= 0xE4) |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
126 |
return GetSpecialPlayerNameString(buffr, index - 0xE4, argv, last); |
1321 | 127 |
break; |
128 |
||
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
129 |
// User defined name |
1321 | 130 |
case 15: |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
131 |
return GetName(buffr, index, last); |
1321 | 132 |
|
4710
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
133 |
case 26: |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
134 |
/* Include string within newgrf text (format code 81) */ |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
135 |
if (HASBIT(index, 10)) { |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
136 |
StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10)); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
137 |
return GetStringWithArgs(buffr, string, argv, last); |
4710
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
138 |
} |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
139 |
break; |
1aa2b507818f
(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents:
4602
diff
changeset
|
140 |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
141 |
case 28: |
4916
b06c18393eca
(svn r6890) - Fix (r6884): Supply last position of the correct buffer...
peter1138
parents:
4912
diff
changeset
|
142 |
GetGRFString(buff, index, lastof(buff)); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
143 |
return FormatString(buffr, buff, argv, 0, last); |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
144 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
145 |
case 29: |
4916
b06c18393eca
(svn r6890) - Fix (r6884): Supply last position of the correct buffer...
peter1138
parents:
4912
diff
changeset
|
146 |
GetGRFString(buff, index + 0x800, lastof(buff)); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
147 |
return FormatString(buffr, buff, argv, 0, last); |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
148 |
|
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
149 |
case 30: |
4916
b06c18393eca
(svn r6890) - Fix (r6884): Supply last position of the correct buffer...
peter1138
parents:
4912
diff
changeset
|
150 |
GetGRFString(buff, index + 0x1000, lastof(buff)); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
151 |
return FormatString(buffr, buff, argv, 0, last); |
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
152 |
|
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
153 |
case 31: |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
154 |
// 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
|
155 |
// 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
|
156 |
if (index < (STR_SPEC_USERSTRING & 0x7FF)) { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
157 |
return strecpy(buffr, _bound_strings[index], last); |
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
|
158 |
} |
1321 | 159 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
160 |
return FormatString(buffr, _userstring, NULL, 0, last); |
0 | 161 |
} |
162 |
||
2639 | 163 |
if (index >= _langtab_num[tab]) { |
1321 | 164 |
error( |
165 |
"!String 0x%X is invalid. " |
|
166 |
"Probably because an old version of the .lng file.\n", string |
|
167 |
); |
|
2639 | 168 |
} |
0 | 169 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
170 |
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8), last); |
0 | 171 |
} |
172 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
173 |
char *GetString(char *buffr, StringID string, const char* last) |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
174 |
{ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
175 |
return GetStringWithArgs(buffr, string, (int32*)_decode_parameters, last); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
176 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
177 |
|
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
178 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
179 |
char *InlineString(char *buf, StringID string) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
180 |
{ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
181 |
buf += Utf8Encode(buf, SCC_STRING_ID); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
182 |
buf += Utf8Encode(buf, string); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
183 |
return buf; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
184 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
185 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
186 |
|
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
|
187 |
// 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
|
188 |
// 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
|
189 |
// 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
|
190 |
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
|
191 |
{ |
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
|
192 |
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
|
193 |
_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
|
194 |
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
|
195 |
} |
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
|
196 |
|
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
|
197 |
// 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
|
198 |
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
|
199 |
{ |
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
|
200 |
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
|
201 |
} |
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
|
202 |
|
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
|
203 |
void InjectDParam(int amount) |
0 | 204 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
205 |
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); |
0 | 206 |
} |
207 |
||
208 |
static const uint32 _divisor_table[] = { |
|
209 |
1000000000, |
|
210 |
100000000, |
|
211 |
10000000, |
|
212 |
1000000, |
|
213 |
||
214 |
100000, |
|
215 |
10000, |
|
216 |
1000, |
|
217 |
100, |
|
218 |
10, |
|
219 |
1 |
|
220 |
}; |
|
221 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
222 |
// TODO |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
223 |
static char *FormatCommaNumber(char *buff, int32 number, const char* last) |
0 | 224 |
{ |
225 |
uint32 quot,divisor; |
|
226 |
int i; |
|
227 |
uint32 tot; |
|
228 |
uint32 num; |
|
229 |
||
230 |
if (number < 0) { |
|
231 |
*buff++ = '-'; |
|
232 |
number = -number; |
|
233 |
} |
|
234 |
||
235 |
num = number; |
|
236 |
||
237 |
tot = 0; |
|
1316 | 238 |
for (i = 0; i != 10; i++) { |
0 | 239 |
divisor = _divisor_table[i]; |
240 |
quot = 0; |
|
241 |
if (num >= divisor) { |
|
242 |
quot = num / _divisor_table[i]; |
|
243 |
num = num % _divisor_table[i]; |
|
244 |
} |
|
1316 | 245 |
if (tot |= quot || i == 9) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
246 |
*buff++ = '0' + quot; |
1316 | 247 |
if (i == 0 || i == 3 || i == 6) *buff++ = ','; |
0 | 248 |
} |
249 |
} |
|
250 |
||
1316 | 251 |
*buff = '\0'; |
0 | 252 |
|
253 |
return buff; |
|
254 |
} |
|
255 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
256 |
// TODO |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
257 |
static char *FormatNoCommaNumber(char *buff, int32 number, const char* last) |
0 | 258 |
{ |
259 |
uint32 quot,divisor; |
|
260 |
int i; |
|
261 |
uint32 tot; |
|
262 |
uint32 num; |
|
263 |
||
264 |
if (number < 0) { |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
265 |
buff = strecpy(buff, "-", last); |
0 | 266 |
number = -number; |
267 |
} |
|
268 |
||
269 |
num = number; |
|
270 |
||
271 |
tot = 0; |
|
1316 | 272 |
for (i = 0; i != 10; i++) { |
0 | 273 |
divisor = _divisor_table[i]; |
274 |
quot = 0; |
|
275 |
if (num >= divisor) { |
|
276 |
quot = num / _divisor_table[i]; |
|
277 |
num = num % _divisor_table[i]; |
|
278 |
} |
|
1316 | 279 |
if (tot |= quot || i == 9) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
280 |
*buff++ = '0' + quot; |
0 | 281 |
} |
282 |
} |
|
283 |
||
1316 | 284 |
*buff = '\0'; |
0 | 285 |
|
286 |
return buff; |
|
287 |
} |
|
288 |
||
289 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
290 |
static char *FormatYmdString(char *buff, Date date, const char* last) |
0 | 291 |
{ |
292 |
YearMonthDay ymd; |
|
293 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
294 |
ConvertDateToYMD(date, &ymd); |
0 | 295 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
296 |
buff = strecpy(buff, GetStringPtr(ymd.day + STR_01AC_1ST - 1), last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
297 |
buff = strecpy(buff, " ", last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
298 |
buff = strecpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
299 |
buff = strecpy(buff, " ", last); |
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
|
300 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
301 |
return FormatNoCommaNumber(buff, ymd.year, last); |
0 | 302 |
} |
303 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
304 |
static char *FormatMonthAndYear(char *buff, Date date, const char* last) |
0 | 305 |
{ |
306 |
YearMonthDay ymd; |
|
307 |
||
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
308 |
ConvertDateToYMD(date, &ymd); |
0 | 309 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
310 |
buff = strecpy(buff, GetStringPtr(STR_MONTH_JAN + ymd.month), last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
311 |
buff = strecpy(buff, " ", last); |
0 | 312 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
313 |
return FormatNoCommaNumber(buff, ymd.year, last); |
0 | 314 |
} |
315 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
316 |
static char *FormatTinyDate(char *buff, Date date, const char* last) |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
317 |
{ |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
318 |
YearMonthDay ymd; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
319 |
|
4289
8981ce44336d
(svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents:
4288
diff
changeset
|
320 |
ConvertDateToYMD(date, &ymd); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
321 |
buff += snprintf( |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
322 |
buff, last - buff + 1, |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
323 |
" %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
324 |
); |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
325 |
|
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
326 |
return buff; |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
327 |
} |
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
328 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
329 |
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last) |
0 | 330 |
{ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
331 |
const char* multiplier = ""; |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
332 |
char buf[40]; |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
333 |
char* p; |
0 | 334 |
int j; |
335 |
||
336 |
// multiply by exchange rate |
|
337 |
number *= spec->rate; |
|
338 |
||
339 |
// convert from negative |
|
1316 | 340 |
if (number < 0) { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
341 |
buff = strecpy(buff, "-", last); |
1316 | 342 |
number = -number; |
343 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
344 |
|
4602
43c44f7df615
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
345 |
/* Add prefix part, folowing symbol_pos specification. |
43c44f7df615
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
346 |
* Here, it can can be either 0 (prefix) or 2 (both prefix anf suffix). |
43c44f7df615
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
347 |
* The only remaining value is 1 (suffix), so everything that is not 1 */ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
348 |
if (spec->symbol_pos != 1) buff = strecpy(buff, spec->prefix, last); |
0 | 349 |
|
350 |
// for huge numbers, compact the number into k or M |
|
351 |
if (compact) { |
|
352 |
if (number >= 1000000000) { |
|
353 |
number = (number + 500000) / 1000000; |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
354 |
multiplier = "M"; |
0 | 355 |
} else if (number >= 1000000) { |
356 |
number = (number + 500) / 1000; |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
357 |
multiplier = "k"; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
358 |
} |
0 | 359 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
360 |
|
0 | 361 |
// convert to ascii number and add commas |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
362 |
p = endof(buf); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
363 |
*--p = '\0'; |
0 | 364 |
j = 4; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
365 |
do { |
1316 | 366 |
if (--j == 0) { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
367 |
*--p = spec->separator; |
1316 | 368 |
j = 3; |
369 |
} |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
370 |
*--p = '0' + number % 10; |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
371 |
} while ((number /= 10) != 0); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
372 |
buff = strecpy(buff, p, last); |
0 | 373 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
374 |
buff = strecpy(buff, multiplier, last); |
0 | 375 |
|
4602
43c44f7df615
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
376 |
/* Add suffix part, folowing symbol_pos specification. |
43c44f7df615
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
377 |
* Here, it can can be either 1 (suffix) or 2 (both prefix anf suffix). |
43c44f7df615
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents:
4505
diff
changeset
|
378 |
* The only remaining value is 1 (prefix), so everything that is not 0 */ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
379 |
if (spec->symbol_pos != 0) buff = strecpy(buff, spec->suffix, last); |
0 | 380 |
|
381 |
return buff; |
|
382 |
} |
|
383 |
||
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
384 |
static int DeterminePluralForm(int32 n) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
385 |
{ |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
386 |
// The absolute value determines plurality |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
387 |
if (n < 0) n = -n; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
388 |
|
2952 | 389 |
switch (_langpack->plural_form) { |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
390 |
// Two forms, singular used for one only |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
391 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
392 |
// Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
393 |
// Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
394 |
case 0: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
395 |
default: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
396 |
return n != 1; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
397 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
398 |
// Only one form |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
399 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
400 |
// Hungarian, Japanese, Korean, Turkish |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
401 |
case 1: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
402 |
return 0; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
403 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
404 |
// Two forms, singular used for zero and one |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
405 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
406 |
// French, Brazilian Portuguese |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
407 |
case 2: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
408 |
return n > 1; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
409 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
410 |
// Three forms, special case for zero |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
411 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
412 |
// Latvian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
413 |
case 3: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
414 |
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
|
415 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
416 |
// Three forms, special case for one and two |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
417 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
418 |
// Gaelige (Irish) |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
419 |
case 4: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
420 |
return n==1 ? 0 : n==2 ? 1 : 2; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
421 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
422 |
// 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
|
423 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
424 |
// Lithuanian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
425 |
case 5: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
426 |
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
|
427 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
428 |
// 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
|
429 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
430 |
// Croatian, Czech, Russian, Slovak, Ukrainian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
431 |
case 6: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
432 |
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
|
433 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
434 |
// 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
|
435 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
436 |
// Polish |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
437 |
case 7: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
438 |
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
|
439 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
440 |
// 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
|
441 |
// Used in: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
442 |
// Slovenian |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
443 |
case 8: |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
444 |
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
|
445 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
446 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
447 |
|
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
448 |
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
|
449 |
{ |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
450 |
//<NUM> {Length of each string} {each string} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
451 |
uint n = (byte)*b++; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
452 |
uint pos,i, mylen=0,mypos=0; |
2952 | 453 |
|
454 |
for (i = pos = 0; i != n; i++) { |
|
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
455 |
uint len = (byte)*b++; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
456 |
if (i == form) { |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
457 |
mypos = pos; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
458 |
mylen = len; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
459 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
460 |
pos += len; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
461 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
462 |
*dstlen = mylen; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
463 |
memcpy(dst, b + mypos, mylen); |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
464 |
return b + pos; |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
465 |
} |
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
466 |
|
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
467 |
typedef struct Units { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
468 |
int s_m; ///< Multiplier for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
469 |
int s_s; ///< Shift for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
470 |
StringID velocity; ///< String for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
471 |
int p_m; ///< Multiplier for power |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
472 |
int p_s; ///< Shift for power |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
473 |
StringID power; ///< String for velocity |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
474 |
int w_m; ///< Multiplier for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
475 |
int w_s; ///< Shift for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
476 |
StringID s_weight; ///< Short string for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
477 |
StringID l_weight; ///< Long string for weight |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
478 |
int v_m; ///< Multiplier for volume |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
479 |
int v_s; ///< Shift for volume |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
480 |
StringID s_volume; ///< Short string for volume |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
StringID force; ///< String for force |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
485 |
} Units; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
486 |
|
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
487 |
/* Unit conversions */ |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
488 |
static const Units units[] = { |
5402
3d37a300486e
(svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents:
5296
diff
changeset
|
489 |
{ // Imperial (Original, mph, hp, metric ton, litre, kN) |
5874
2db89a640b7a
(svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents:
5814
diff
changeset
|
490 |
1, 0, STR_UNITS_VELOCITY_IMPERIAL, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
491 |
1, 0, STR_UNITS_POWER_IMPERIAL, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
492 |
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
|
493 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
5402
3d37a300486e
(svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents:
5296
diff
changeset
|
494 |
1, 0, STR_UNITS_FORCE_SI, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
495 |
}, |
5402
3d37a300486e
(svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents:
5296
diff
changeset
|
496 |
{ // Metric (km/h, hp, metric ton, litre, kN) |
5874
2db89a640b7a
(svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents:
5814
diff
changeset
|
497 |
103, 6, STR_UNITS_VELOCITY_METRIC, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
498 |
1, 0, STR_UNITS_POWER_METRIC, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
499 |
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
|
500 |
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, |
5402
3d37a300486e
(svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents:
5296
diff
changeset
|
501 |
1, 0, STR_UNITS_FORCE_SI, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
502 |
}, |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
503 |
{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton) |
5874
2db89a640b7a
(svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents:
5814
diff
changeset
|
504 |
1831, 12, STR_UNITS_VELOCITY_SI, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
505 |
764, 10, STR_UNITS_POWER_SI, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
506 |
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
|
507 |
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
|
508 |
1, 0, STR_UNITS_FORCE_SI, |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
509 |
}, |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
510 |
}; |
2082
1e289843fe0b
(svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents:
2075
diff
changeset
|
511 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
512 |
static char* FormatString(char* buff, const char* str, const int32* argv, uint casei, const char* last) |
0 | 513 |
{ |
4840
a76d40e0aea4
(svn r6766) -Codechange: Move _openttd_revision[] into the functions that use it instead of global
Darkvater
parents:
4710
diff
changeset
|
514 |
extern const char _openttd_revision[]; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
515 |
WChar b; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
516 |
const int32 *argv_orig = argv; |
2087 | 517 |
uint modifier = 0; |
0 | 518 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
519 |
while ((b = Utf8Consume(&str)) != '\0') { |
1316 | 520 |
switch (b) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
521 |
case SCC_SETX: // {SETX} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
522 |
if (buff + Utf8CharLen(SCC_SETX) + 1 < last) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
523 |
buff += Utf8Encode(buff, SCC_SETX); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
524 |
*buff++ = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
525 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
526 |
break; |
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
527 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
528 |
case SCC_SETXY: // {SETXY} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
529 |
if (buff + Utf8CharLen(SCC_SETXY) + 2 < last) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
530 |
buff += Utf8Encode(buff, SCC_SETXY); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
531 |
*buff++ = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
532 |
*buff++ = *str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
533 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
534 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
535 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
536 |
case SCC_STRING_ID: // {STRINL} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
537 |
buff = GetStringWithArgs(buff, Utf8Consume(&str), argv, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
538 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
539 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
540 |
case SCC_DATE_LONG: // {DATE_LONG} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
541 |
buff = FormatYmdString(buff, GetInt32(&argv), last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
542 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
543 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
544 |
case SCC_DATE_SHORT: // {DATE_SHORT} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
545 |
buff = FormatMonthAndYear(buff, GetInt32(&argv), last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
546 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
547 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
548 |
case SCC_VELOCITY: {// {VELOCITY} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
549 |
int32 args[1]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
550 |
assert(_opt_ptr->units < lengthof(units)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
551 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
552 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
553 |
modifier = 0; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
554 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
555 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
556 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
557 |
case SCC_CURRENCY_COMPACT: /* {CURRCOMPACT} */ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
558 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true, last); |
0 | 559 |
break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
560 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
561 |
case SCC_REVISION: /* {REV} */ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
562 |
buff = strecpy(buff, _openttd_revision, last); |
0 | 563 |
break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
564 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
565 |
case SCC_CARGO_SHORT: { /* {SHORTCARGO} */ |
236
da0ae9d977e0
(svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents:
233
diff
changeset
|
566 |
// Short description of cargotypes. Layout: |
0 | 567 |
// 8-bit = cargo type |
568 |
// 16-bit = cargo count |
|
3616
65f9ec8fe4fb
(svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents:
3601
diff
changeset
|
569 |
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
|
570 |
switch (cargo_str) { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
571 |
case STR_TONS: { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
572 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
573 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
574 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
575 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
576 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
577 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
578 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
579 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
580 |
case STR_LITERS: { |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
581 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
582 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
583 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
584 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
585 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
586 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
587 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
588 |
|
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
589 |
default: |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
590 |
buff = FormatCommaNumber(buff, GetInt32(&argv), last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
591 |
buff = strecpy(buff, " ", last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
592 |
buff = strecpy(buff, GetStringPtr(cargo_str), last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
593 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
594 |
} |
1316 | 595 |
} break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
596 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
597 |
case SCC_CURRENCY_COMPACT_64: { /* {CURRCOMPACT64} */ |
236
da0ae9d977e0
(svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents:
233
diff
changeset
|
598 |
// 64 bit compact currency-unit |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
599 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last); |
0 | 600 |
break; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
601 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
602 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
603 |
case SCC_STRING1: { /* {STRING1} */ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
604 |
// String that consumes ONE argument |
2087 | 605 |
uint str = modifier + GetInt32(&argv); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
606 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1), last); |
2087 | 607 |
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
|
608 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
609 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
610 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
611 |
case SCC_STRING2: { /* {STRING2} */ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
612 |
// String that consumes TWO arguments |
2087 | 613 |
uint str = modifier + GetInt32(&argv); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
614 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2), last); |
2087 | 615 |
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
|
616 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
617 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
618 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
619 |
case SCC_STRING3: { /* {STRING3} */ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
620 |
// String that consumes THREE arguments |
2087 | 621 |
uint str = modifier + GetInt32(&argv); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
622 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3), last); |
2087 | 623 |
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
|
624 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
625 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
626 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
627 |
case SCC_STRING4: { /* {STRING4} */ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
628 |
// String that consumes FOUR arguments |
2087 | 629 |
uint str = modifier + GetInt32(&argv); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
630 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4), last); |
2087 | 631 |
modifier = 0; |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
632 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
633 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
634 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
635 |
case SCC_STRING5: { /* {STRING5} */ |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
636 |
// String that consumes FIVE arguments |
2087 | 637 |
uint str = modifier + GetInt32(&argv); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
638 |
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5), last); |
2087 | 639 |
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
|
640 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
641 |
} |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
642 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
643 |
case SCC_STATION_FEATURES: { /* {STATIONFEATURES} */ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
644 |
buff = StationGetSpecialString(buff, GetInt32(&argv), last); |
2063
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
645 |
break; |
ae866a12f2df
(svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents:
2057
diff
changeset
|
646 |
} |
0 | 647 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
648 |
case SCC_INDUSTRY_NAME: { /* {INDUSTRY} */ |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
649 |
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
|
650 |
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
|
651 |
|
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
652 |
// 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
|
653 |
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
|
654 |
|
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
655 |
// 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
|
656 |
// 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
|
657 |
args[0] = i->town->index; |
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4920
diff
changeset
|
658 |
args[1] = GetIndustrySpec(i->type)->name; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
659 |
buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24, last); |
2087 | 660 |
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
|
661 |
break; |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
662 |
} |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2063
diff
changeset
|
663 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
664 |
case SCC_VOLUME: { // {VOLUME} |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
665 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
666 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
667 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
668 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last); |
2087 | 669 |
modifier = 0; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
670 |
break; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
671 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
672 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
673 |
case SCC_GENDER_LIST: { // {G 0 Der Die Das} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
674 |
const char* s = 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
|
675 |
int len; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
676 |
int gender = 0; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
677 |
if (s != NULL && Utf8Consume(&s) == SCC_GENDER_INDEX) gender = (byte)s[0]; |
2084
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
678 |
str = ParseStringChoice(str, gender, buff, &len); |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
679 |
buff += len; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
680 |
break; |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
681 |
} |
65639f898a50
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2082
diff
changeset
|
682 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
683 |
case SCC_DATE_TINY: { // {DATE_TINY} |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
684 |
buff = FormatTinyDate(buff, GetInt32(&argv), last); |
2087 | 685 |
break; |
686 |
} |
|
687 |
||
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
688 |
case SCC_CARGO: { // {CARGO} |
2087 | 689 |
// Layout now is: |
690 |
// 8bit - cargo type |
|
691 |
// 16-bit - cargo count |
|
4898
e3962fe14ef8
(svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents:
4840
diff
changeset
|
692 |
CargoID cargo = GetInt32(&argv); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
693 |
StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : _cargoc.names_long[cargo]; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
694 |
buff = GetStringWithArgs(buff, cargo_str, argv++, last); |
2087 | 695 |
break; |
696 |
} |
|
697 |
||
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
698 |
case SCC_POWER: { // {POWER} |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
699 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
700 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
701 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
702 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24, last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
703 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
704 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
705 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
706 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
707 |
case SCC_VOLUME_SHORT: { // {VOLUME_S} |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
708 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
709 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
710 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
711 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24, last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
712 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
713 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
714 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
715 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
716 |
case SCC_WEIGHT: { // {WEIGHT} |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
717 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
718 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
719 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
720 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
721 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
722 |
break; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
723 |
} |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
724 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
725 |
case SCC_WEIGHT_SHORT: { // {WEIGHT_S} |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
726 |
int32 args[1]; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
727 |
assert(_opt_ptr->units < lengthof(units)); |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
728 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
729 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24, last); |
3342
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
730 |
modifier = 0; |
cb9b5c6dd74c
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents:
3329
diff
changeset
|
731 |
break; |
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 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
734 |
case SCC_FORCE: { // {FORCE} |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
735 |
int32 args[1]; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
736 |
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
|
737 |
args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
738 |
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24, last); |
3489
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
739 |
modifier = 0; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
740 |
break; |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
741 |
} |
497361c60b90
(svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents:
3485
diff
changeset
|
742 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
743 |
case SCC_SKIP: // {SKIP} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
744 |
argv++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
745 |
break; |
2410
795225af3c72
(svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents:
2353
diff
changeset
|
746 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
747 |
// This sets up the gender for the string. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
748 |
// We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
749 |
case SCC_GENDER_INDEX: // {GENDER 0} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
750 |
str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
751 |
break; |
2630 | 752 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
753 |
case SCC_STRING: {// {STRING} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
754 |
uint str = modifier + GetInt32(&argv); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
755 |
// WARNING. It's prohibited for the included string to consume any arguments. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
756 |
// For included strings that consume argument, you should use STRING1, STRING2 etc. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
757 |
// To debug stuff you can set argv to NULL and it will tell you |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
758 |
buff = GetStringWithArgs(buff, str, argv, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
759 |
modifier = 0; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
760 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
761 |
} |
2087 | 762 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
763 |
case SCC_COMMA: // {COMMA} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
764 |
buff = FormatCommaNumber(buff, GetInt32(&argv), last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
765 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
766 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
767 |
case SCC_ARG_INDEX: // Move argument pointer |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
768 |
argv = argv_orig + (byte)*str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
769 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
770 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
771 |
case SCC_PLURAL_LIST: { // {P} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
772 |
int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
773 |
int len; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
774 |
str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
775 |
buff += len; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
776 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
777 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
778 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
779 |
case SCC_NUM: // {NUM} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
780 |
buff = FormatNoCommaNumber(buff, GetInt32(&argv), last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
781 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
782 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
783 |
case SCC_CURRENCY: // {CURRENCY} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
784 |
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
785 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
786 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
787 |
case SCC_WAYPOINT_NAME: { // {WAYPOINT} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
788 |
int32 temp[2]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
789 |
Waypoint *wp = GetWaypoint(GetInt32(&argv)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
790 |
StringID str; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
791 |
if (wp->string != STR_NULL) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
792 |
str = wp->string; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
793 |
} else { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
794 |
temp[0] = wp->town_index; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
795 |
temp[1] = wp->town_cn + 1; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
796 |
str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL; |
2087 | 797 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
798 |
buff = GetStringWithArgs(buff, str, temp, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
799 |
break; |
0 | 800 |
} |
1097
196431cb50fe
(svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents:
1093
diff
changeset
|
801 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
802 |
case SCC_STATION_NAME: { // {STATION} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
803 |
const Station* st = GetStation(GetInt32(&argv)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
804 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
805 |
if (!IsValidStation(st)) { // station doesn't exist anymore |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
806 |
buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
807 |
} else { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
808 |
int32 temp[2]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
809 |
temp[0] = st->town->townnametype; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
810 |
temp[1] = st->town->townnameparts; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
811 |
buff = GetStringWithArgs(buff, st->string_id, temp, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
812 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
813 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
814 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
815 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
816 |
case SCC_TOWN_NAME: { // {TOWN} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
817 |
const Town* t = GetTown(GetInt32(&argv)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
818 |
int32 temp[1]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
819 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
820 |
assert(IsValidTown(t)); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
821 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
822 |
temp[0] = t->townnameparts; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
823 |
buff = GetStringWithArgs(buff, t->townnametype, temp, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
824 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
825 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
826 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
827 |
case SCC_CURRENCY_64: { // {CURRENCY64} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
828 |
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
829 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
830 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
831 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
832 |
case SCC_SETCASE: { // {SETCASE} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
833 |
// This is a pseudo command, it's outputted when someone does {STRING.ack} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
834 |
// The modifier is added to all subsequent GetStringWithArgs that accept the modifier. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
835 |
modifier = (byte)*str++ << 24; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
836 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
837 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
838 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
839 |
case SCC_SWITCH_CASE: { // {Used to implement case switching} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
840 |
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT> |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
841 |
// Each LEN is printed using 2 bytes in big endian order. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
842 |
uint num = (byte)*str++; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
843 |
while (num) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
844 |
if ((byte)str[0] == casei) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
845 |
// Found the case, adjust str pointer and continue |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
846 |
str += 3; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
847 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
848 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
849 |
// Otherwise skip to the next case |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
850 |
str += 3 + (str[1] << 8) + str[2]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
851 |
num--; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
852 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
853 |
break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
854 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
855 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
856 |
default: |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
857 |
if (buff + Utf8CharLen(b) < last) buff += Utf8Encode(buff, b); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
858 |
break; |
0 | 859 |
} |
860 |
} |
|
1316 | 861 |
*buff = '\0'; |
0 | 862 |
return buff; |
863 |
} |
|
864 |
||
865 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
866 |
static char *StationGetSpecialString(char *buff, int x, const char* last) |
0 | 867 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
868 |
if ((x & 0x01) && (buff + Utf8CharLen(SCC_TRAIN) < last)) buff += Utf8Encode(buff, SCC_TRAIN); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
869 |
if ((x & 0x02) && (buff + Utf8CharLen(SCC_LORRY) < last)) buff += Utf8Encode(buff, SCC_LORRY); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
870 |
if ((x & 0x04) && (buff + Utf8CharLen(SCC_BUS) < last)) buff += Utf8Encode(buff, SCC_BUS); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
871 |
if ((x & 0x08) && (buff + Utf8CharLen(SCC_PLANE) < last)) buff += Utf8Encode(buff, SCC_PLANE); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
872 |
if ((x & 0x10) && (buff + Utf8CharLen(SCC_SHIP) < last)) buff += Utf8Encode(buff, SCC_SHIP); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
873 |
*buff = '\0'; |
0 | 874 |
return buff; |
875 |
} |
|
876 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
877 |
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last) |
1316 | 878 |
{ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
879 |
char name[512]; |
0 | 880 |
|
4920
67f6806ce054
(svn r6896) - Fix (r6895): Supply last position of the correct buffer *again*
peter1138
parents:
4919
diff
changeset
|
881 |
_town_name_generators[ind](name, seed, lastof(name)); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
882 |
return strecpy(buff, name, last); |
0 | 883 |
} |
884 |
||
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
|
885 |
static const char* const _silly_company_names[] = { |
0 | 886 |
"Bloggs Brothers", |
887 |
"Tiny Transport Ltd.", |
|
888 |
"Express Travel", |
|
889 |
"Comfy-Coach & Co.", |
|
890 |
"Crush & Bump Ltd.", |
|
891 |
"Broken & Late Ltd.", |
|
892 |
"Sam Speedy & Son", |
|
893 |
"Supersonic Travel", |
|
894 |
"Mike's Motors", |
|
895 |
"Lightning International", |
|
896 |
"Pannik & Loozit Ltd.", |
|
897 |
"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
|
898 |
"Getout & Pushit Ltd." |
0 | 899 |
}; |
900 |
||
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
|
901 |
static const char* const _surname_list[] = { |
0 | 902 |
"Adams", |
903 |
"Allan", |
|
904 |
"Baker", |
|
905 |
"Bigwig", |
|
906 |
"Black", |
|
907 |
"Bloggs", |
|
908 |
"Brown", |
|
909 |
"Campbell", |
|
910 |
"Gordon", |
|
911 |
"Hamilton", |
|
912 |
"Hawthorn", |
|
913 |
"Higgins", |
|
914 |
"Green", |
|
915 |
"Gribble", |
|
916 |
"Jones", |
|
917 |
"McAlpine", |
|
918 |
"MacDonald", |
|
919 |
"McIntosh", |
|
920 |
"Muir", |
|
921 |
"Murphy", |
|
922 |
"Nelson", |
|
923 |
"O'Donnell", |
|
924 |
"Parker", |
|
925 |
"Phillips", |
|
926 |
"Pilkington", |
|
927 |
"Quigley", |
|
928 |
"Sharkey", |
|
929 |
"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
|
930 |
"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
|
931 |
}; |
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
|
932 |
|
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
|
933 |
static const char* const _silly_surname_list[] = { |
0 | 934 |
"Grumpy", |
935 |
"Dozy", |
|
936 |
"Speedy", |
|
937 |
"Nosey", |
|
938 |
"Dribble", |
|
939 |
"Mushroom", |
|
940 |
"Cabbage", |
|
941 |
"Sniffle", |
|
942 |
"Fishy", |
|
943 |
"Swindle", |
|
944 |
"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
|
945 |
"Nutkins" |
0 | 946 |
}; |
947 |
||
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
948 |
static const char _initial_name_letters[] = { |
1321 | 949 |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', |
950 |
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', |
|
0 | 951 |
}; |
952 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
953 |
static char *GenAndCoName(char *buff, uint32 arg, const char* last) |
0 | 954 |
{ |
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
|
955 |
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
|
956 |
uint num; |
0 | 957 |
|
1704
6054160187df
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
958 |
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
|
959 |
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
|
960 |
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
|
961 |
} 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
|
962 |
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
|
963 |
num = lengthof(_surname_list); |
0 | 964 |
} |
965 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
966 |
buff = strecpy(buff, base[num * GB(arg, 16, 8) >> 8], last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
967 |
buff = strecpy(buff, " & Co.", last); |
0 | 968 |
|
969 |
return buff; |
|
970 |
} |
|
971 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
972 |
static char *GenPresidentName(char *buff, uint32 x, const char* last) |
0 | 973 |
{ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
974 |
char initial[] = "?. "; |
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
|
975 |
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
|
976 |
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
|
977 |
uint i; |
0 | 978 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
979 |
initial[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8]; |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
980 |
buff = strecpy(buff, initial, last); |
0 | 981 |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2140
diff
changeset
|
982 |
i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8; |
0 | 983 |
if (i < sizeof(_initial_name_letters)) { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
984 |
initial[0] = _initial_name_letters[i]; |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
985 |
buff = strecpy(buff, initial, last); |
0 | 986 |
} |
987 |
||
1704
6054160187df
(svn r2208) - Fix: [ 1174237 ] Max loan always in euros, use _opt_ptr instead of _opt (glx)
Darkvater
parents:
1625
diff
changeset
|
988 |
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
|
989 |
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
|
990 |
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
|
991 |
} 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
|
992 |
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
|
993 |
num = lengthof(_surname_list); |
0 | 994 |
} |
995 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
996 |
buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], last); |
0 | 997 |
|
998 |
return buff; |
|
999 |
} |
|
1000 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1001 |
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last) |
0 | 1002 |
{ |
1316 | 1003 |
switch (ind) { |
1321 | 1004 |
case 1: // not used |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1005 |
return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], last); |
0 | 1006 |
|
1321 | 1007 |
case 2: // used for Foobar & Co company names |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1008 |
return GenAndCoName(buff, GetInt32(&argv), last); |
0 | 1009 |
|
1321 | 1010 |
case 3: // President name |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1011 |
return GenPresidentName(buff, GetInt32(&argv), last); |
0 | 1012 |
|
1321 | 1013 |
case 4: // song names |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1014 |
return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, last); |
0 | 1015 |
} |
1016 |
||
1017 |
// town name? |
|
1316 | 1018 |
if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1019 |
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv), last); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1020 |
return strecpy(buff, " Transport", last); |
0 | 1021 |
} |
1022 |
||
1023 |
// language name? |
|
1024 |
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) { |
|
1025 |
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
|
1026 |
return strecpy(buff, |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1027 |
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, last); |
0 | 1028 |
} |
1029 |
||
1030 |
// resolution size? |
|
1031 |
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { |
|
1032 |
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1033 |
buff += snprintf( |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1034 |
buff, last - buff + 1, "%dx%d", _resolutions[i][0], _resolutions[i][1] |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1035 |
); |
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1036 |
return buff; |
0 | 1037 |
} |
1038 |
||
1039 |
// screenshot format name? |
|
1040 |
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) { |
|
1041 |
int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4); |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4898
diff
changeset
|
1042 |
return strecpy(buff, GetScreenshotFormatDesc(i), last); |
0 | 1043 |
} |
1044 |
||
1045 |
assert(0); |
|
1046 |
return NULL; |
|
1047 |
} |
|
1048 |
||
1049 |
// remap a string ID from the old format to the new format |
|
1050 |
StringID RemapOldStringID(StringID s) |
|
1051 |
{ |
|
1321 | 1052 |
switch (s) { |
1053 |
case 0x0006: return STR_SV_EMPTY; |
|
1054 |
case 0x7000: return STR_SV_UNNAMED; |
|
1055 |
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1056 |
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH; |
|
1057 |
case 0x8864: return STR_SV_TRAIN_NAME; |
|
1058 |
case 0x902B: return STR_SV_ROADVEH_NAME; |
|
1059 |
case 0x9830: return STR_SV_SHIP_NAME; |
|
1060 |
case 0xA02F: return STR_SV_AIRCRAFT_NAME; |
|
1061 |
||
1062 |
default: |
|
2951 | 1063 |
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) { |
1321 | 1064 |
return s - 0x300F + STR_SV_STNAME; |
2951 | 1065 |
} else { |
1321 | 1066 |
return s; |
2951 | 1067 |
} |
1321 | 1068 |
} |
0 | 1069 |
} |
1070 |
||
1316 | 1071 |
bool ReadLanguagePack(int lang_index) |
1072 |
{ |
|
0 | 1073 |
int tot_count, i; |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1074 |
LanguagePack *lang_pack; |
0 | 1075 |
size_t len; |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1076 |
char **langpack_offs; |
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1077 |
char *s; |
0 | 1078 |
|
1079 |
{ |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5167
diff
changeset
|
1080 |
char *lang = str_fmt("%s%s", _paths.lang_dir, _dynlang.ent[lang_index].file); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1081 |
lang_pack = (LanguagePack*)ReadFileToMem(lang, &len, 200000); |
0 | 1082 |
free(lang); |
1083 |
} |
|
1084 |
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
|
1085 |
if (len < sizeof(LanguagePack) || |
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1086 |
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
|
1087 |
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
0 | 1088 |
free(lang_pack); |
1089 |
return false; |
|
1090 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
64
diff
changeset
|
1091 |
|
0 | 1092 |
#if defined(TTD_BIG_ENDIAN) |
1316 | 1093 |
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
|
1094 |
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]); |
0 | 1095 |
} |
1096 |
#endif |
|
1097 |
||
1098 |
tot_count = 0; |
|
1316 | 1099 |
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
|
1100 |
uint num = lang_pack->offsets[i]; |
0 | 1101 |
_langtab_start[i] = tot_count; |
1102 |
_langtab_num[i] = num; |
|
1103 |
tot_count += num; |
|
1104 |
} |
|
1105 |
||
1106 |
// Allocate offsets |
|
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
1107 |
langpack_offs = MallocT<char*>(tot_count); |
0 | 1108 |
|
1109 |
// Fill offsets |
|
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1110 |
s = lang_pack->data; |
1316 | 1111 |
for (i = 0; i != tot_count; i++) { |
1312
594340ca5b87
(svn r1816) Use char instead of byte for string formatting
tron
parents:
1311
diff
changeset
|
1112 |
len = (byte)*s; |
1316 | 1113 |
*s++ = '\0'; // zero terminate the string before. |
1114 |
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++; |
|
0 | 1115 |
langpack_offs[i] = s; |
1116 |
s += len; |
|
1117 |
} |
|
1118 |
||
1321 | 1119 |
free(_langpack); |
0 | 1120 |
_langpack = lang_pack; |
1121 |
||
1321 | 1122 |
free(_langpack_offs); |
0 | 1123 |
_langpack_offs = langpack_offs; |
1124 |
||
1125 |
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file)); |
|
1126 |
||
1127 |
_dynlang.curr = lang_index; |
|
3601
138bf309cf27
(svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
3489
diff
changeset
|
1128 |
SetCurrentGrfLangID(_langpack->isocode); |
0 | 1129 |
return true; |
1130 |
} |
|
1131 |
||
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
|
1132 |
/** 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
|
1133 |
* 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
|
1134 |
* 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
|
1135 |
* @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
|
1136 |
* 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
|
1137 |
* @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
|
1138 |
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
|
1139 |
{ |
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
|
1140 |
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
|
1141 |
|
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
|
1142 |
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
|
1143 |
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
|
1144 |
|
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
|
1145 |
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
|
1146 |
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
|
1147 |
|
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
|
1148 |
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
|
1149 |
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
|
1150 |
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
|
1151 |
} |
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
|
1152 |
|
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
|
1153 |
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
|
1154 |
} |
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
|
1155 |
|
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1156 |
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
|
1157 |
{ |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1158 |
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
|
1159 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1160 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1161 |
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
|
1162 |
{ |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1163 |
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
|
1164 |
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
|
1165 |
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
|
1166 |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5167
diff
changeset
|
1167 |
dir = opendir(_paths.lang_dir); |
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1168 |
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
|
1169 |
while ((dirent = readdir(dir)) != NULL) { |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5108
diff
changeset
|
1170 |
const char *d_name = FS2OTTD(dirent->d_name); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1171 |
const char *t = strrchr(d_name, '.'); |
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1172 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1173 |
if (t != NULL && strcmp(t, ".lng") == 0) { |
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
5108
diff
changeset
|
1174 |
languages[num++] = strdup(d_name); |
4219
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1175 |
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
|
1176 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1177 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1178 |
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
|
1179 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1180 |
|
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1181 |
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
|
1182 |
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
|
1183 |
} |
72768a8f3a97
(svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents:
4120
diff
changeset
|
1184 |
|
0 | 1185 |
// 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
|
1186 |
void InitializeLanguagePacks(void) |
0 | 1187 |
{ |
1188 |
DynamicLanguages *dl = &_dynlang; |
|
1321 | 1189 |
int i; |
1190 |
int n; |
|
1191 |
int m; |
|
1192 |
int def; |
|
4505
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1193 |
int def2; |
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
|
1194 |
int fallback; |
1319
beeef5cce0e4
(svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents:
1318
diff
changeset
|
1195 |
LanguagePack hdr; |
0 | 1196 |
FILE *in; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4942
diff
changeset
|
1197 |
char *files[MAX_LANG]; |
4505
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1198 |
const char* lang; |
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
|
1199 |
|
4505
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1200 |
lang = GetCurrentLocale("LC_MESSAGES"); |
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1201 |
if (lang == NULL) lang = "en_GB"; |
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
|
1202 |
|
0 | 1203 |
n = GetLanguageList(files, lengthof(files)); |
1204 |
||
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
|
1205 |
def = -1; |
4505
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1206 |
def2 = -1; |
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
|
1207 |
fallback = 0; |
0 | 1208 |
|
1209 |
// go through the language files and make sure that they are valid. |
|
1316 | 1210 |
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
|
1211 |
size_t j; |
1321 | 1212 |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5167
diff
changeset
|
1213 |
char *s = str_fmt("%s%s", _paths.lang_dir, files[i]); |
0 | 1214 |
in = fopen(s, "rb"); |
1215 |
free(s); |
|
1316 | 1216 |
if (in == NULL || |
0 | 1217 |
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 || |
1218 |
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) || |
|
1219 |
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) { |
|
1220 |
free(files[i]); |
|
1221 |
continue; |
|
1222 |
} |
|
1223 |
||
1224 |
dl->ent[m].file = files[i]; |
|
1225 |
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
|
1226 |
|
4505
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1227 |
if (strcmp(hdr.isocode, "en_GB") == 0) fallback = m; |
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1228 |
if (strncmp(hdr.isocode, lang, 2) == 0) def2 = m; |
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1229 |
if (strncmp(hdr.isocode, lang, 5) == 0) def = m; |
0 | 1230 |
|
1231 |
m++; |
|
1232 |
} |
|
4505
abb08e94a1ea
(svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents:
4503
diff
changeset
|
1233 |
if (def == -1) def = (def2 != -1 ? def2 : fallback); |
0 | 1234 |
|
1235 |
if (m == 0) |
|
1236 |
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
|
1237 |
|
0 | 1238 |
dl->num = m; |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
2966
diff
changeset
|
1239 |
for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i; |
0 | 1240 |
dl->dropdown[i] = INVALID_STRING_ID; |
1241 |
||
1316 | 1242 |
for (i = 0; i != dl->num; i++) |
1243 |
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) { |
|
0 | 1244 |
def = i; |
1245 |
break; |
|
1246 |
} |
|
1247 |
||
1248 |
if (!ReadLanguagePack(def)) |
|
1249 |
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
|
1250 |
} |