strings.c
author truelight
Thu, 24 Mar 2005 14:43:40 +0000
changeset 1540 6eef12dab5bf
parent 1376 d4e1dd8eb7e5
child 1542 62a03537ad0b
permissions -rw-r--r--
(svn r2044) -Fix: fix that TriggerVehicle is called from the wrong user
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.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
     3
#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
     4
#include "strings.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 504
diff changeset
     5
#include "table/strings.h"
1306
7768d8361d88 (svn r1810) Move town name generation declarations into a header of their own
tron
parents: 1102
diff changeset
     6
#include "namegen.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "vehicle.h"
6
e9b56d50aa99 (svn r7) -Feature [1003350] Euro introduction news item. (dominik81)
darkvater
parents: 0
diff changeset
    10
#include "news.h"
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 425
diff changeset
    11
#include "screenshot.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
    13
static char *StationGetSpecialString(char *buff);
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
    14
static char *GetSpecialTownNameString(char *buff, int ind);
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
    15
static char *GetSpecialPlayerNameString(char *buff, int ind);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
    17
static char *DecodeString(char *buff, const char *str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
663
80c66fd07863 (svn r1098) -Fix: server without revision build doesn't care about the client's version. Also moved all revision things where it belongs (network.c)
darkvater
parents: 659
diff changeset
    19
extern const char _openttd_revision[];
659
a9733f856cd0 (svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
darkvater
parents: 656
diff changeset
    20
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    21
typedef struct LanguagePack {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	uint32 ident;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	uint32 version;			// 32-bits of auto generated version info which is basically a hash of strings.h
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	char name[32];			// the international name of this language
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	char own_name[32];	// the localized name of this language
1376
d4e1dd8eb7e5 (svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents: 1321
diff changeset
    26
	char isocode[16];	// the ISO code for the language (not country code)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	uint16 offsets[32];	// the offsets
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    28
	char data[VARARRAY_SIZE];
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    29
} LanguagePack;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    30
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    31
static char **_langpack_offs;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    32
static LanguagePack *_langpack;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    33
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
    34
static uint _langtab_start[32]; // Offset into langpack offs
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
    36
const StringID _currency_string_list[] = {
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    37
	STR_CURR_GBP,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    38
	STR_CURR_USD,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    39
	STR_CURR_EUR,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	STR_CURR_YEN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	STR_CURR_ATS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	STR_CURR_BEF,
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    43
	STR_CURR_CHF,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    44
	STR_CURR_CZK,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    45
	STR_CURR_DEM,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	STR_CURR_DKK,
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    47
	STR_CURR_ESP,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	STR_CURR_FIM,
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    49
	STR_CURR_FRF,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	STR_CURR_GRD,
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    51
	STR_CURR_HUF,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    52
	STR_CURR_ISK,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	STR_CURR_ITL,
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    54
	STR_CURR_NLG,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    55
	STR_CURR_NOK,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    56
	STR_CURR_PLN,
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    57
	STR_CURR_ROL,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	STR_CURR_RUR,
762
ef014856bd88 (svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents: 759
diff changeset
    59
	STR_CURR_SEK,
759
a445474d7c21 (svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents: 663
diff changeset
    60
	STR_CURR_CUSTOM,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	INVALID_STRING_ID
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
    64
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = {
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    65
	{ /* LT_NORMAL */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    66
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    67
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    68
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    69
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    70
		STR_ITEMS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    71
		STR_CRATES,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    72
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    73
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    74
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    75
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    76
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    77
		STR_RES_OTHER
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    78
	},
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    79
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    80
	{ /* LT_HILLY */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    81
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    82
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    83
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    84
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    85
		STR_ITEMS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    86
		STR_CRATES,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    87
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    88
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    89
		STR_RES_OTHER,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    90
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    91
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    92
		STR_TONS
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    93
	},
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    94
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    95
	{ /* LT_DESERT */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    96
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    97
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    98
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
    99
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   100
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   101
		STR_CRATES,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   102
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   103
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   104
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   105
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   106
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   107
		STR_TONS
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   108
	},
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   109
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   110
	{ /* LT_CANDY */
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   111
		STR_PASSENGERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   112
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   113
		STR_BAGS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   114
		STR_NOTHING,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   115
		STR_NOTHING,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   116
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   117
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   118
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   119
		STR_TONS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   120
		STR_NOTHING,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   121
		STR_LITERS,
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   122
		STR_NOTHING
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   123
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   126
static char *str_cat(char *dst, const char *src)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
{
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   128
	while ((*dst++ = *src++) != '\0') {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
	return dst - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   132
static const char *GetStringPtr(StringID string)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   137
char *GetString(char *buffr, StringID string)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	uint index = string & 0x7FF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	uint tab = string >> 11;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   142
	switch (string) {
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   143
		case 0:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   144
			error("!invalid string id 0 in GetString");
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   145
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   147
		case 0x30D1:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   148
			return StationGetSpecialString(buffr);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   150
		case STR_SPEC_SCREENSHOT_NAME:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   151
			return DecodeString(buffr, _screenshot_name);
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   152
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   154
	switch (tab) {
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   155
		case 4:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   156
			if (index >= 0xC0) return GetSpecialTownNameString(buffr, index - 0xC0);
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   157
			break;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   158
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   159
		case 14:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   160
			if (index >= 0xE4) return GetSpecialPlayerNameString(buffr, index - 0xE4);
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   161
			break;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   162
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   163
		case 15:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   164
			return GetName(index, buffr);
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   165
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   166
		case 31: // special or dynamic strings
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   167
			return DecodeString(buffr, _userstring);
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   168
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   169
		default:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   170
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	if (index >= _langtab_num[tab])
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   174
		error(
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   175
			"!String 0x%X is invalid. "
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   176
			"Probably because an old version of the .lng file.\n", string
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   177
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	return DecodeString(buffr, GetStringPtr(string));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
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
   182
void InjectDParam(int amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   184
	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
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
   188
int32 GetParamInt32(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   190
	int32 result = GetDParam(0);
425
97d601c182f0 (svn r624) Merge r377 to trunk:
tron
parents: 410
diff changeset
   191
	memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
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
   195
static int64 GetParamInt64(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   197
	int64 result = GetDParam(0) + ((uint64)GetDParam(1) << 32);
425
97d601c182f0 (svn r624) Merge r377 to trunk:
tron
parents: 410
diff changeset
   198
	memmove(&_decode_parameters[0], &_decode_parameters[2], sizeof(uint32) * (lengthof(_decode_parameters)-2));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
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
   203
int GetParamInt16(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   205
	int result = (int16)GetDParam(0);
425
97d601c182f0 (svn r624) Merge r377 to trunk:
tron
parents: 410
diff changeset
   206
	memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
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
   210
int GetParamInt8(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   212
	int result = (int8)GetDParam(0);
425
97d601c182f0 (svn r624) Merge r377 to trunk:
tron
parents: 410
diff changeset
   213
	memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
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
   217
int GetParamUint16(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
{
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   219
	int result = GetDParam(0);
425
97d601c182f0 (svn r624) Merge r377 to trunk:
tron
parents: 410
diff changeset
   220
	memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
static const uint32 _divisor_table[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	1000000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	100000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	10000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	1000000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	100000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	10000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	1000,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	100,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   238
static char *FormatCommaNumber(char *buff, int32 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	uint32 quot,divisor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	uint32 tot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	uint32 num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	if (number < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		*buff++ = '-';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	tot = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   253
	for (i = 0; i != 10; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		divisor = _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		quot = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
		if (num >= divisor) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			quot = num / _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			num = num % _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   260
		if (tot |= quot || i == 9) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   261
			*buff++ = '0' + quot;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   262
			if (i == 0 || i == 3 || i == 6) *buff++ = ',';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   266
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   271
static char *FormatNoCommaNumber(char *buff, int32 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	uint32 quot,divisor;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	uint32 tot;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
	uint32 num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	if (number < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		*buff++ = '-';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	tot = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   286
	for (i = 0; i != 10; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
		divisor = _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
		quot = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		if (num >= divisor) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
			quot = num / _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
			num = num % _divisor_table[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   293
		if (tot |= quot || i == 9) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   294
			*buff++ = '0' + quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   298
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   304
static char *FormatYmdString(char *buff, uint16 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
{
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   306
	const char *src;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	YearMonthDay ymd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	ConvertDayToYMD(&ymd, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   311
	for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   312
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	buff[-1] = ' ';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	buff[3] = ' ';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
970
24abd02b1092 (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 919
diff changeset
   317
	return FormatNoCommaNumber(buff+4, ymd.year + MAX_YEAR_BEGIN_REAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   320
static char *FormatMonthAndYear(char *buff, uint16 number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	const char *src;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	YearMonthDay ymd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	ConvertDayToYMD(&ymd, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   327
	for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	buff[-1] = ' ';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
970
24abd02b1092 (svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents: 919
diff changeset
   330
	return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   333
static char *FormatTinyDate(char *buff, uint16 number)
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   334
{
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   335
	YearMonthDay ymd;
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   336
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   337
	ConvertDayToYMD(&ymd, number);
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   338
	buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL);
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   339
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   340
	return buff;
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   341
}
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   342
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
   343
uint GetCurrentCurrencyRate(void)
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 970
diff changeset
   344
{
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   345
	return _currency_specs[_opt.currency].rate;
26
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 6
diff changeset
   346
}
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 6
diff changeset
   347
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   348
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	const char *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	char c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	char buf[40], *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	// multiply by exchange rate
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	number *= spec->rate;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	// convert from negative
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   359
	if (number < 0) {
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   360
		*buff++ = '-';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   361
		number = -number;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   362
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   363
788
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   364
	// add prefix part
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   365
	s = spec->prefix;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   366
	while (s != spec->prefix + lengthof(spec->prefix) && (c = *s++) != '\0') *buff++ = c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	// for huge numbers, compact the number into k or M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	if (compact) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		compact = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
		if (number >= 1000000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
			number = (number + 500000) / 1000000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
			compact = 'M';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
		} else if (number >= 1000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			number = (number + 500) / 1000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			compact = 'k';
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   377
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   379
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	// convert to ascii number and add commas
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	p = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	j = 4;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   383
	do {
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   384
		if (--j == 0) {
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   385
			*p++ = spec->separator;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   386
			j = 3;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   387
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		*p++ = '0' + number % 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	} while (number /= 10);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	do *buff++ = *--p; while (p != buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
	if (compact) *buff++ = compact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
788
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   394
	// add suffix part
951b52443d48 (svn r1255) Renamed "postfix" to "suffix", for strings and variable names
dominik
parents: 762
diff changeset
   395
	s = spec->suffix;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   396
	while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   401
static char *DecodeString(char *buff, const char *str)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	byte b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   405
	while ((b = *str++) != '\0') {
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   406
		switch (b) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
		case 0x1: // {SETX}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
			*buff++ = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
			*buff++ = *str++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		case 0x2: // {SETXY}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			*buff++ = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
			*buff++ = *str++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
			*buff++ = *str++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
		case 0x7B: // {COMMA32}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
			buff = FormatCommaNumber(buff, GetParamInt32());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
		case 0x7C: // {COMMA16}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
			buff = FormatCommaNumber(buff, GetParamInt16());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
		case 0x7D: // {COMMA8}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
			buff = FormatCommaNumber(buff, GetParamInt8());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
		case 0x7E: // {NUMU16}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
			buff = FormatNoCommaNumber(buff, GetParamInt16());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
		case 0x7F: // {CURRENCY}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
			buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
		// 0x80 is reserved for EURO
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
		case 0x81: // {STRINL}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
			str += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
			buff = GetString(buff, READ_LE_UINT16(str-2));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
		case 0x82: // {DATE_LONG}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
			buff = FormatYmdString(buff, GetParamUint16());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
		case 0x83: // {DATE_SHORT}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
			buff = FormatMonthAndYear(buff, GetParamUint16());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
		case 0x84: {// {VELOCITY}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
			int value = GetParamInt16();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
			if (_opt.kilometers) value = value * 1648 >> 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
			buff = FormatCommaNumber(buff, value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
			if (_opt.kilometers) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
				memcpy(buff, " km/h", 5);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
				buff += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
				memcpy(buff, " mph", 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
				buff += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   455
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   456
		// 0x85 is used as escape character..
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		case 0x85:
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   458
			switch (*str++) {
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   459
			case 0: /* {CURRCOMPACT} */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
				buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
				break;
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   462
			case 1: /* {INT32} */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
				buff = FormatNoCommaNumber(buff, GetParamInt32());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
				break;
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   465
			case 2: /* {REV} */
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   466
				buff = str_cat(buff, _openttd_revision);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
				break;
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   468
			case 3: { /* {SHORTCARGO} */
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   469
				// Short description of cargotypes. Layout:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
				// 8-bit = cargo type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
				// 16-bit = cargo count
1318
4830fe56f601 (svn r1822) Const correctness
tron
parents: 1317
diff changeset
   472
				const char *s;
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   473
				StringID cargo_str = _cargo_string_list[_opt.landscape][(byte)GetParamInt8()];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
				// liquid type of cargo is multiplied by 100 to get correct amount
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   476
				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
				s = GetStringPtr(cargo_str);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   478
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
				memcpy(buff++, " ", 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
				while (*s) *buff++ = *s++;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   481
			} break;
236
da0ae9d977e0 (svn r237) -Fix: [1025836] Company value problem (again). Now company value rightly shows the value, including ALL your money.
darkvater
parents: 233
diff changeset
   482
			case 4: /* {CURRCOMPACT64} */
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
   483
				// 64 bit compact currency-unit
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
   484
				buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
			default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
				error("!invalid escape sequence in string");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		case 0x86: // {SKIP}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
			GetParamInt16();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
			//assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
		case 0x87: { // {VOLUME}
1318
4830fe56f601 (svn r1822) Const correctness
tron
parents: 1317
diff changeset
   497
			const char *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
			buff = FormatCommaNumber(buff, GetParamInt16() * 1000);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
			memcpy(buff++, " ", 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
			s = GetStringPtr(STR_LITERS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
			while (*s) *buff++ = *s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   504
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
		case 0x88: // {STRING}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
			buff = GetString(buff, (uint16)GetParamUint16());
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
		case 0x99: { // {CARGO}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
			// Layout now is:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
			//   8bit   - cargo type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
			//   16-bit - cargo count
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
			int cargo_str = _cargoc.names_long_s[GetParamInt8()];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
			// Now check if the cargo count is 1, if it is, increase string by 32.
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   515
			if (GetDParam(0) != 1) cargo_str += 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
			buff = GetString(buff, cargo_str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
		case 0x9A: { // {STATION}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
			Station *st;
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
   522
			InjectDParam(1);
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 788
diff changeset
   523
			st = GetStation(GetDParam(1));
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   524
			if (st->xy == 0) { // station doesn't exist anymore
64
93656f16d50a (svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents: 26
diff changeset
   525
				buff = GetString(buff, STR_UNKNOWN_DESTINATION);
93656f16d50a (svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents: 26
diff changeset
   526
				break;
93656f16d50a (svn r65) -Fix [1009567] problem with transferred cargo crashes game. Invalid st->xy on deleted station.
darkvater
parents: 26
diff changeset
   527
			}
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   528
			SetDParam(0, st->town->townnametype);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   529
			SetDParam(1, st->town->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
			buff = GetString(buff, st->string_id);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
		case 0x9B: { // {TOWN}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
			Town *t;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 788
diff changeset
   535
			t = GetTown(GetDParam(0));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
			assert(t->xy);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   537
			SetDParam(0, t->townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
			buff = GetString(buff, t->townnametype);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
		case 0x9C: { // {CURRENCY64}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   543
			buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 287
diff changeset
   547
		case 0x9D: { // {WAYPOINT}
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   548
			Waypoint *cp = &_waypoints[GetDParam(0)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
			StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
			int idx;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
			if (~cp->town_or_string & 0xC000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
				GetParamInt32(); // skip it
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
				str = cp->town_or_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
				idx = (cp->town_or_string >> 8) & 0x3F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
				if (idx == 0) {
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 287
diff changeset
   557
					str = STR_WAYPOINTNAME_CITY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
				} else {
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
   559
					InjectDParam(1);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   560
					SetDParam(1, idx + 1);
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 287
diff changeset
   561
					str = STR_WAYPOINTNAME_CITY_SERIAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
				}
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   563
				SetDParam(0, cp->town_or_string & 0xFF);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
			buff = GetString(buff, str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
		} break;
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   568
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   569
		case 0x9E: { // {DATE_TINY}
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   570
			buff = FormatTinyDate(buff, GetParamUint16());
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   571
			break;
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   572
		}
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   573
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
		// case 0x88..0x98: // {COLORS}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		// case 0xE: // {TINYFONT}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
		// case 0xF: // {BIGFONT}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		// 0x9E is the highest number that is available.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
			*buff++ = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   582
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   587
static char *StationGetSpecialString(char *buff)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	int x = GetParamInt8();
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   590
	if (x & 0x01) *buff++ = '\xB4';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   591
	if (x & 0x02) *buff++ = '\xB5';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   592
	if (x & 0x04) *buff++ = '\xB6';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   593
	if (x & 0x08) *buff++ = '\xB7';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   594
	if (x & 0x10) *buff++ = '\xB8';
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   595
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   599
static char *GetSpecialTownNameString(char *buff, int ind)
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   600
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	uint32 x = GetParamInt32();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   602
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	_town_name_generators[ind](buff, x);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   605
	while (*buff != '\0') buff++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
static const char * const _silly_company_names[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	"Bloggs Brothers",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
	"Tiny Transport Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
	"Express Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	"Comfy-Coach & Co.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	"Crush & Bump Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	"Broken & Late Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	"Sam Speedy & Son",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	"Supersonic Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	"Mike's Motors",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	"Lightning International",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	"Pannik & Loozit Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	"Inter-City Transport",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	"Getout & Pushit Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
static const char * const _surname_list[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	"Adams",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	"Allan",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
	"Baker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	"Bigwig",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	"Black",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
	"Bloggs",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	"Brown",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	"Campbell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
	"Gordon",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	"Hamilton",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
	"Hawthorn",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
	"Higgins",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	"Green",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	"Gribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
	"Jones",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	"McAlpine",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	"MacDonald",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	"McIntosh",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	"Muir",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	"Murphy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	"Nelson",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	"O'Donnell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	"Parker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	"Phillips",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	"Pilkington",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
	"Quigley",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	"Sharkey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	"Thomson",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	"Watkins",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	"Grumpy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
	"Dozy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	"Speedy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	"Nosey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	"Dribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	"Mushroom",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	"Cabbage",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	"Sniffle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	"Fishy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	"Swindle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	"Sneaky",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	"Nutkins",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   669
static const char _initial_name_letters[] = {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   670
	'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   671
	'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W',
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   674
static char *GenAndCoName(char *buff)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	uint32 x = GetParamInt32();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	uint base,num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	base = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	num = 29;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	if (_opt.landscape == LT_CANDY) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
		base = num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
		num = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	buff = str_cat(buff, " & Co.");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   692
static char *GenPlayerName_4(char *buff)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	uint32 x = GetParamInt32();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	uint i, base, num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   697
	buff[0] = _initial_name_letters[(sizeof(_initial_name_letters) * (byte)x) >> 8];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	buff[1] = '.';
233
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   699
	buff[2] = ' '; // Insert a space after initial and period "I. Firstname" instead of "I.Firstname"
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   700
	buff += 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	i = ((sizeof(_initial_name_letters) + 35) * (byte)(x >> 8)) >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	if (i < sizeof(_initial_name_letters)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
		buff[0] = _initial_name_letters[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
		buff[1] = '.';
233
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   706
		buff[2] = ' '; // Insert a space after initial and period "I. J. Firstname" instead of "I.J.Firstname"
dd177a8c9f19 (svn r234) -Fix: added missing romanian.txt to VC6, VS.NET and Jamfile project file
darkvater
parents: 193
diff changeset
   707
		buff += 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	base = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
	num = 29;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
	if (_opt.landscape == LT_CANDY) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
		base = num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
		num = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
static const char * const _song_names[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
	"Tycoon DELUXE Theme",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	"Easy Driver",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	"Little Red Diesel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	"Cruise Control",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
	"Don't Walk!",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	"Fell Apart On Me",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
	"City Groove",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	"Funk Central",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	"Stoke It",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	"Road Hog",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	"Aliens Ate My Railway",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
	"Snarl Up",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
	"Stroll On",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	"Can't Get There From Here",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
	"Sawyer's Tune",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
	"Hold That Train!",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
	"Movin' On",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
	"Goss Groove",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
	"Small Town",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
	"Broomer's Oil Rag",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	"Jammit",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
	"Hard Drivin'"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   747
static char *GetSpecialPlayerNameString(char *buff, int ind)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
{
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   749
	switch (ind) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   750
		case 1: // not used
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   751
			return str_cat(buff, _silly_company_names[GetParamInt32() & 0xFFFF]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   753
		case 2: // used for Foobar & Co company names
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   754
			return GenAndCoName(buff);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   756
		case 3: // President name
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   757
			return GenPlayerName_4(buff);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   759
		case 4: // song names
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   760
			return str_cat(buff, _song_names[GetParamUint16() - 1]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	// town name?
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   764
	if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
		buff = GetSpecialTownNameString(buff, ind - 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
		return str_cat(buff, " Transport");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	// language name?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
	if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
   772
		return str_cat(buff, i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
	// resolution size?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
		return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	// screenshot format name?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
	if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
		int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
		return str_cat(buff, GetScreenshotFormatDesc(i));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
// remap a string ID from the old format to the new format
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
StringID RemapOldStringID(StringID s)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
{
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   794
	switch (s) {
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   795
		case 0x0006: return STR_SV_EMPTY;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   796
		case 0x7000: return STR_SV_UNNAMED;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   797
		case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   798
		case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   799
		case 0x8864: return STR_SV_TRAIN_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   800
		case 0x902B: return STR_SV_ROADVEH_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   801
		case 0x9830: return STR_SV_SHIP_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   802
		case 0xA02F: return STR_SV_AIRCRAFT_NAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   803
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   804
		default:
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   805
			if (IS_INT_INSIDE(s, 0x300F, 0x3030))
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   806
				return s - 0x300F + STR_SV_STNAME;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   807
			else
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   808
				return s;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   809
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   812
bool ReadLanguagePack(int lang_index)
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   813
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
	int tot_count, i;
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
   815
	LanguagePack *lang_pack;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	size_t len;
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   817
	char **langpack_offs;
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   818
	char *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
		char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		lang_pack = ReadFileToMem(lang, &len, 100000);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		free(lang);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	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
   826
	if (len < sizeof(LanguagePack) ||
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
   827
			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
   828
			lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
		free(lang_pack);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   832
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
#if defined(TTD_BIG_ENDIAN)
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   834
	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
   835
		lang_pack->offsets[i] = READ_LE_UINT16(&lang_pack->offsets[i]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
	tot_count = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   840
	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
   841
		uint num = lang_pack->offsets[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		_langtab_start[i] = tot_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
		_langtab_num[i] = num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
		tot_count += num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
	// Allocate offsets
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   848
	langpack_offs = malloc(tot_count * sizeof(*langpack_offs));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
	// Fill offsets
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
   851
	s = lang_pack->data;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   852
	for (i = 0; i != tot_count; i++) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   853
		len = (byte)*s;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   854
		*s++ = '\0'; // zero terminate the string before.
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   855
		if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
		langpack_offs[i] = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		s += len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   860
	free(_langpack);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	_langpack = lang_pack;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   863
	free(_langpack_offs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	_langpack_offs = langpack_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
	_dynlang.curr = lang_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
// 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
   874
void InitializeLanguagePacks(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	DynamicLanguages *dl = &_dynlang;
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   877
	int i;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   878
	int n;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   879
	int m;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   880
	int def;
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
   881
	LanguagePack hdr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	FILE *in;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
	char *files[32];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	n = GetLanguageList(files, lengthof(files));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	def = 0; // default language file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	// go through the language files and make sure that they are valid.
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   890
	for (i = m = 0; i != n; i++) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   891
		int j;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   892
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
		char *s = str_fmt("%s%s", _path.lang_dir, files[i]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
		in = fopen(s, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
		free(s);
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   896
		if (in == NULL ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
				(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
				hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
				hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
			free(files[i]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
			continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
		dl->ent[m].file = files[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
		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
   906
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   907
		if (strcmp(hdr.name, "English") == 0) def = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
		m++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	if (m == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		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
   914
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	dl->num = m;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   916
	for (i = 0; i != dl->num; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
		dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	dl->dropdown[i] = INVALID_STRING_ID;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   920
	for (i = 0; i != dl->num; i++)
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   921
		if (strcmp(dl->ent[i].file, dl->curr_file) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
			def = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
	if (!ReadLanguagePack(def))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
		error("can't read language pack '%s'", dl->ent[def].file);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
}