2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-08-06 14:59:54 +00:00
|
|
|
#include "currency.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-02-06 13:41:02 +00:00
|
|
|
#include "string.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-02-05 23:03:12 +00:00
|
|
|
#include "namegen.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "station.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "vehicle.h"
|
2004-08-10 15:00:15 +00:00
|
|
|
#include "news.h"
|
2004-11-15 19:25:59 +00:00
|
|
|
#include "screenshot.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "waypoint.h"
|
2005-07-15 18:30:13 +00:00
|
|
|
#include "industry.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-04-21 03:00:20 +00:00
|
|
|
#include "newgrf_text.h"
|
2006-04-22 01:37:31 +00:00
|
|
|
#include "table/landscape_const.h"
|
2006-07-07 02:44:51 +00:00
|
|
|
#include "music.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-04 23:45:20 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
/* for opendir/readdir/closedir */
|
|
|
|
# include "fios.h"
|
|
|
|
#else
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <dirent.h>
|
|
|
|
#endif /* WIN32 */
|
|
|
|
|
2005-07-26 19:04:19 +00:00
|
|
|
char _userstring[128];
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static char *StationGetSpecialString(char *buff, int x);
|
|
|
|
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed);
|
|
|
|
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-15 16:51:55 +00:00
|
|
|
extern const char _openttd_revision[];
|
2004-12-15 00:31:08 +00:00
|
|
|
|
2005-02-06 14:47:56 +00:00
|
|
|
typedef struct LanguagePack {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 ident;
|
2006-08-28 18:53:03 +00:00
|
|
|
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h
|
|
|
|
char name[32]; // the international name of this language
|
|
|
|
char own_name[32]; // the localized name of this language
|
|
|
|
char isocode[16]; // the ISO code for the language (not country code)
|
|
|
|
uint16 offsets[32]; // the offsets
|
|
|
|
byte plural_form; // how to compute plural forms
|
|
|
|
byte pad[3]; // pad header to be a multiple of 4
|
2005-02-06 14:47:56 +00:00
|
|
|
char data[VARARRAY_SIZE];
|
|
|
|
} LanguagePack;
|
|
|
|
|
|
|
|
static char **_langpack_offs;
|
|
|
|
static LanguagePack *_langpack;
|
|
|
|
static uint _langtab_num[32]; // Offset into langpack offs
|
|
|
|
static uint _langtab_start[32]; // Offset into langpack offs
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = {
|
2005-02-06 11:23:41 +00:00
|
|
|
{ /* LT_NORMAL */
|
|
|
|
STR_PASSENGERS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_ITEMS,
|
|
|
|
STR_CRATES,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_RES_OTHER
|
|
|
|
},
|
|
|
|
|
|
|
|
{ /* LT_HILLY */
|
|
|
|
STR_PASSENGERS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_ITEMS,
|
|
|
|
STR_CRATES,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_RES_OTHER,
|
|
|
|
STR_TONS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_TONS
|
|
|
|
},
|
|
|
|
|
|
|
|
{ /* LT_DESERT */
|
|
|
|
STR_PASSENGERS,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_CRATES,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_TONS
|
|
|
|
},
|
|
|
|
|
|
|
|
{ /* LT_CANDY */
|
|
|
|
STR_PASSENGERS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_BAGS,
|
|
|
|
STR_NOTHING,
|
|
|
|
STR_NOTHING,
|
|
|
|
STR_TONS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_TONS,
|
|
|
|
STR_NOTHING,
|
|
|
|
STR_LITERS,
|
|
|
|
STR_NOTHING
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// Read an int64 from the argv array.
|
|
|
|
static inline int64 GetInt64(const int32 **argv)
|
|
|
|
{
|
|
|
|
int64 result;
|
|
|
|
|
|
|
|
assert(argv);
|
|
|
|
result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32);
|
|
|
|
(*argv)+=2;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read an int32 from the argv array.
|
|
|
|
static inline int32 GetInt32(const int32 **argv)
|
|
|
|
{
|
|
|
|
assert(argv);
|
|
|
|
return *(*argv)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read an array from the argv array.
|
|
|
|
static inline const int32 *GetArgvPtr(const int32 **argv, int n)
|
|
|
|
{
|
|
|
|
const int32 *result;
|
|
|
|
assert(*argv);
|
|
|
|
result = *argv;
|
|
|
|
(*argv) += n;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-14 09:43:59 +00:00
|
|
|
#define NUM_BOUND_STRINGS 8
|
|
|
|
|
|
|
|
// Array to hold the bound strings.
|
|
|
|
static const char *_bound_strings[NUM_BOUND_STRINGS];
|
|
|
|
|
|
|
|
// This index is used to implement a "round-robin" allocating of
|
|
|
|
// slots for BindCString. NUM_BOUND_STRINGS slots are reserved.
|
|
|
|
// Which means that after NUM_BOUND_STRINGS calls to BindCString,
|
|
|
|
// the indices will be reused.
|
|
|
|
static int _bind_index;
|
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
static const char *GetStringPtr(StringID string)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
// The highest 8 bits of string contain the "case index".
|
|
|
|
// These 8 bits will only be set when FormatString wants to print
|
|
|
|
// the string in a different case. No one else except FormatString
|
2006-08-26 20:54:30 +00:00
|
|
|
// should set those bits, therefore string CANNOT be StringID, but uint32.
|
2006-08-27 10:04:33 +00:00
|
|
|
static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-20 15:29:28 +00:00
|
|
|
uint index = GB(string, 0, 11);
|
|
|
|
uint tab = GB(string, 11, 5);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 08:09:57 +00:00
|
|
|
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
switch (tab) {
|
|
|
|
case 4:
|
2005-07-15 14:53:44 +00:00
|
|
|
if (index >= 0xC0)
|
|
|
|
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv));
|
2005-02-06 16:56:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 14:
|
2005-07-15 14:53:44 +00:00
|
|
|
if (index >= 0xE4)
|
|
|
|
return GetSpecialPlayerNameString(buffr, index - 0xE4, argv);
|
2005-02-06 16:56:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// User defined name
|
2005-02-06 16:56:04 +00:00
|
|
|
case 15:
|
|
|
|
return GetName(index, buffr);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-21 03:00:20 +00:00
|
|
|
case 28:
|
|
|
|
return GetGRFString(buffr, index);
|
|
|
|
|
|
|
|
case 29:
|
|
|
|
return GetGRFString(buffr, index + 0x800);
|
|
|
|
|
|
|
|
case 30:
|
|
|
|
return GetGRFString(buffr, index + 0x1000);
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
case 31:
|
|
|
|
// dynamic strings. These are NOT to be passed through the formatter,
|
|
|
|
// but passed through verbatim.
|
2005-07-14 09:43:59 +00:00
|
|
|
if (index < (STR_SPEC_USERSTRING & 0x7FF)) {
|
2005-07-15 14:53:44 +00:00
|
|
|
return strecpy(buffr, _bound_strings[index], NULL);
|
2005-07-14 09:43:59 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
return FormatString(buffr, _userstring, NULL, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (index >= _langtab_num[tab]) {
|
2005-02-06 16:56:04 +00:00
|
|
|
error(
|
|
|
|
"!String 0x%X is invalid. "
|
|
|
|
"Probably because an old version of the .lng file.\n", string
|
|
|
|
);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 08:09:57 +00:00
|
|
|
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8));
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *GetString(char *buffr, StringID string)
|
|
|
|
{
|
|
|
|
return GetStringWithArgs(buffr, string, (int32*)_decode_parameters);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-14 09:43:59 +00:00
|
|
|
// This function takes a C-string and allocates a temporary string ID.
|
|
|
|
// The duration of the bound string is valid only until the next GetString,
|
|
|
|
// so be careful.
|
|
|
|
StringID BindCString(const char *str)
|
|
|
|
{
|
|
|
|
int idx = (++_bind_index) & (NUM_BOUND_STRINGS - 1);
|
|
|
|
_bound_strings[idx] = str;
|
|
|
|
return idx + STR_SPEC_DYNSTRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is used to "bind" a C string to a OpenTTD dparam slot.
|
|
|
|
void SetDParamStr(uint n, const char *str)
|
|
|
|
{
|
|
|
|
SetDParam(n, BindCString(str));
|
|
|
|
}
|
|
|
|
|
2005-02-06 08:18:00 +00:00
|
|
|
void InjectDParam(int amount)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-10 19:02:27 +00:00
|
|
|
memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32 _divisor_table[] = {
|
|
|
|
1000000000,
|
|
|
|
100000000,
|
|
|
|
10000000,
|
|
|
|
1000000,
|
|
|
|
|
|
|
|
100000,
|
|
|
|
10000,
|
|
|
|
1000,
|
|
|
|
100,
|
|
|
|
10,
|
|
|
|
1
|
|
|
|
};
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *FormatCommaNumber(char *buff, int32 number)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint32 quot,divisor;
|
|
|
|
int i;
|
|
|
|
uint32 tot;
|
|
|
|
uint32 num;
|
|
|
|
|
|
|
|
if (number < 0) {
|
|
|
|
*buff++ = '-';
|
|
|
|
number = -number;
|
|
|
|
}
|
|
|
|
|
|
|
|
num = number;
|
|
|
|
|
|
|
|
tot = 0;
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != 10; i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
divisor = _divisor_table[i];
|
|
|
|
quot = 0;
|
|
|
|
if (num >= divisor) {
|
|
|
|
quot = num / _divisor_table[i];
|
|
|
|
num = num % _divisor_table[i];
|
|
|
|
}
|
2005-02-06 11:23:41 +00:00
|
|
|
if (tot |= quot || i == 9) {
|
2005-02-06 09:52:06 +00:00
|
|
|
*buff++ = '0' + quot;
|
2005-02-06 11:23:41 +00:00
|
|
|
if (i == 0 || i == 3 || i == 6) *buff++ = ',';
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
*buff = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *FormatNoCommaNumber(char *buff, int32 number)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint32 quot,divisor;
|
|
|
|
int i;
|
|
|
|
uint32 tot;
|
|
|
|
uint32 num;
|
|
|
|
|
|
|
|
if (number < 0) {
|
|
|
|
*buff++ = '-';
|
|
|
|
number = -number;
|
|
|
|
}
|
|
|
|
|
|
|
|
num = number;
|
|
|
|
|
|
|
|
tot = 0;
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != 10; i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
divisor = _divisor_table[i];
|
|
|
|
quot = 0;
|
|
|
|
if (num >= divisor) {
|
|
|
|
quot = num / _divisor_table[i];
|
|
|
|
num = num % _divisor_table[i];
|
|
|
|
}
|
2005-02-06 11:23:41 +00:00
|
|
|
if (tot |= quot || i == 9) {
|
2005-02-06 09:52:06 +00:00
|
|
|
*buff++ = '0' + quot;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
*buff = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
static char *FormatYmdString(char *buff, Date date)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-06 09:52:06 +00:00
|
|
|
const char *src;
|
2004-08-09 17:04:08 +00:00
|
|
|
YearMonthDay ymd;
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
ConvertDateToYMD(date, &ymd);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {}
|
2006-05-12 19:30:49 +00:00
|
|
|
buff[-1] = ' ';
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-05-12 19:30:49 +00:00
|
|
|
for (src = GetStringPtr(STR_0162_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
|
2004-08-09 17:04:08 +00:00
|
|
|
buff[-1] = ' ';
|
|
|
|
|
2006-08-16 11:39:55 +00:00
|
|
|
return FormatNoCommaNumber(buff, ymd.year);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
static char *FormatMonthAndYear(char *buff, Date date)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const char *src;
|
|
|
|
YearMonthDay ymd;
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
ConvertDateToYMD(date, &ymd);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
for (src = GetStringPtr(STR_MONTH_JAN + ymd.month); (*buff++ = *src++) != '\0';) {}
|
2004-08-09 17:04:08 +00:00
|
|
|
buff[-1] = ' ';
|
|
|
|
|
2006-08-16 11:39:55 +00:00
|
|
|
return FormatNoCommaNumber(buff, ymd.year);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
static char *FormatTinyDate(char *buff, Date date)
|
2005-01-22 23:13:20 +00:00
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
ConvertDateToYMD(date, &ymd);
|
2006-08-16 11:39:55 +00:00
|
|
|
buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year);
|
2005-01-22 23:13:20 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
char c;
|
|
|
|
char buf[40], *p;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
// multiply by exchange rate
|
|
|
|
number *= spec->rate;
|
|
|
|
|
|
|
|
// convert from negative
|
2005-02-06 11:23:41 +00:00
|
|
|
if (number < 0) {
|
|
|
|
*buff++ = '-';
|
|
|
|
number = -number;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
/* add prefix part, only if it is specified by symbol_pos */
|
|
|
|
if (spec->symbol_pos == 0) {
|
|
|
|
s = spec->prefix;
|
|
|
|
while (s != spec->prefix + lengthof(spec->prefix) && (c = *(s++)) != '\0') *(buff)++ = c;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// for huge numbers, compact the number into k or M
|
|
|
|
if (compact) {
|
|
|
|
compact = 0;
|
|
|
|
if (number >= 1000000000) {
|
|
|
|
number = (number + 500000) / 1000000;
|
|
|
|
compact = 'M';
|
|
|
|
} else if (number >= 1000000) {
|
|
|
|
number = (number + 500) / 1000;
|
|
|
|
compact = 'k';
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// convert to ascii number and add commas
|
|
|
|
p = buf;
|
|
|
|
j = 4;
|
2004-09-10 19:02:27 +00:00
|
|
|
do {
|
2005-02-06 11:23:41 +00:00
|
|
|
if (--j == 0) {
|
|
|
|
*p++ = spec->separator;
|
|
|
|
j = 3;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
*p++ = '0' + number % 10;
|
|
|
|
} while (number /= 10);
|
|
|
|
do *buff++ = *--p; while (p != buf);
|
|
|
|
|
|
|
|
if (compact) *buff++ = compact;
|
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
/* add suffix part, only if it is specified by symbol_pos */
|
|
|
|
if (spec->symbol_pos != 0) {
|
|
|
|
s = spec->suffix;
|
|
|
|
while (s != spec->suffix + lengthof(spec->suffix) && (c = *(s++)) != '\0') *(buff++) = c;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
static int DeterminePluralForm(int32 n)
|
|
|
|
{
|
|
|
|
// The absolute value determines plurality
|
|
|
|
if (n < 0) n = -n;
|
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (_langpack->plural_form) {
|
2005-07-16 17:12:32 +00:00
|
|
|
// Two forms, singular used for one only
|
|
|
|
// Used in:
|
|
|
|
// Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish,
|
|
|
|
// Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
return n != 1;
|
|
|
|
|
|
|
|
// Only one form
|
|
|
|
// Used in:
|
|
|
|
// Hungarian, Japanese, Korean, Turkish
|
|
|
|
case 1:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Two forms, singular used for zero and one
|
|
|
|
// Used in:
|
|
|
|
// French, Brazilian Portuguese
|
|
|
|
case 2:
|
|
|
|
return n > 1;
|
|
|
|
|
|
|
|
// Three forms, special case for zero
|
|
|
|
// Used in:
|
|
|
|
// Latvian
|
|
|
|
case 3:
|
|
|
|
return n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;
|
|
|
|
|
|
|
|
// Three forms, special case for one and two
|
|
|
|
// Used in:
|
|
|
|
// Gaelige (Irish)
|
|
|
|
case 4:
|
|
|
|
return n==1 ? 0 : n==2 ? 1 : 2;
|
|
|
|
|
|
|
|
// Three forms, special case for numbers ending in 1[2-9]
|
|
|
|
// Used in:
|
|
|
|
// Lithuanian
|
|
|
|
case 5:
|
|
|
|
return n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2;
|
|
|
|
|
|
|
|
// Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
|
|
|
|
// Used in:
|
|
|
|
// Croatian, Czech, Russian, Slovak, Ukrainian
|
|
|
|
case 6:
|
|
|
|
return n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
|
|
|
|
|
|
|
|
// Three forms, special case for one and some numbers ending in 2, 3, or 4
|
|
|
|
// Used in:
|
|
|
|
// Polish
|
|
|
|
case 7:
|
|
|
|
return n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
|
|
|
|
|
|
|
|
// Four forms, special case for one and all numbers ending in 02, 03, or 04
|
|
|
|
// Used in:
|
|
|
|
// Slovenian
|
|
|
|
case 8:
|
|
|
|
return n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
|
|
|
|
{
|
|
|
|
//<NUM> {Length of each string} {each string}
|
|
|
|
uint n = (byte)*b++;
|
|
|
|
uint pos,i, mylen=0,mypos=0;
|
2006-02-01 07:36:15 +00:00
|
|
|
|
|
|
|
for (i = pos = 0; i != n; i++) {
|
2005-07-16 17:12:32 +00:00
|
|
|
uint len = (byte)*b++;
|
|
|
|
if (i == form) {
|
|
|
|
mypos = pos;
|
|
|
|
mylen = len;
|
|
|
|
}
|
|
|
|
pos += len;
|
|
|
|
}
|
|
|
|
*dstlen = mylen;
|
|
|
|
memcpy(dst, b + mypos, mylen);
|
|
|
|
return b + pos;
|
|
|
|
}
|
|
|
|
|
2006-03-26 21:50:57 +00:00
|
|
|
typedef struct Units {
|
|
|
|
int s_m; ///< Multiplier for velocity
|
|
|
|
int s_s; ///< Shift for velocity
|
|
|
|
StringID velocity; ///< String for velocity
|
|
|
|
int p_m; ///< Multiplier for power
|
|
|
|
int p_s; ///< Shift for power
|
|
|
|
StringID power; ///< String for velocity
|
|
|
|
int w_m; ///< Multiplier for weight
|
|
|
|
int w_s; ///< Shift for weight
|
|
|
|
StringID s_weight; ///< Short string for weight
|
|
|
|
StringID l_weight; ///< Long string for weight
|
|
|
|
int v_m; ///< Multiplier for volume
|
|
|
|
int v_s; ///< Shift for volume
|
|
|
|
StringID s_volume; ///< Short string for volume
|
|
|
|
StringID l_volume; ///< Long string for volume
|
2006-04-09 18:25:31 +00:00
|
|
|
int f_m; ///< Multiplier for force
|
|
|
|
int f_s; ///< Shift for force
|
|
|
|
StringID force; ///< String for force
|
2006-03-26 21:50:57 +00:00
|
|
|
} Units;
|
|
|
|
|
2006-04-09 18:25:31 +00:00
|
|
|
/* Unit conversions */
|
2006-03-26 21:50:57 +00:00
|
|
|
static const Units units[] = {
|
2006-04-09 18:25:31 +00:00
|
|
|
{ // Imperial (Original, mph, hp, metric ton, litre, metric ton force)
|
2006-04-08 12:04:23 +00:00
|
|
|
10, 4, STR_UNITS_VELOCITY_IMPERIAL,
|
2006-03-26 21:50:57 +00:00
|
|
|
1, 0, STR_UNITS_POWER_IMPERIAL,
|
|
|
|
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
|
|
|
|
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
|
2006-04-09 18:25:31 +00:00
|
|
|
835, 13, STR_UNITS_FORCE_METRIC,
|
2006-03-26 21:50:57 +00:00
|
|
|
},
|
2006-04-09 18:25:31 +00:00
|
|
|
{ // Metric (km/h, hp, metric ton, litre, metric ton force)
|
2006-04-08 12:04:23 +00:00
|
|
|
1, 0, STR_UNITS_VELOCITY_METRIC,
|
2006-03-26 21:50:57 +00:00
|
|
|
1, 0, STR_UNITS_POWER_METRIC,
|
|
|
|
1, 0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
|
|
|
|
1000, 0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
|
2006-04-09 18:25:31 +00:00
|
|
|
835, 13, STR_UNITS_FORCE_METRIC,
|
2006-03-26 21:50:57 +00:00
|
|
|
},
|
2006-04-09 18:25:31 +00:00
|
|
|
{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton)
|
2006-04-08 12:04:23 +00:00
|
|
|
284, 10, STR_UNITS_VELOCITY_SI,
|
2006-03-26 21:50:57 +00:00
|
|
|
764, 10, STR_UNITS_POWER_SI,
|
|
|
|
1000, 0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
|
2006-04-09 14:49:45 +00:00
|
|
|
1, 0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
|
2006-04-09 18:25:31 +00:00
|
|
|
1, 0, STR_UNITS_FORCE_SI,
|
2006-03-26 21:50:57 +00:00
|
|
|
},
|
|
|
|
};
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte b;
|
2005-07-15 14:53:44 +00:00
|
|
|
const int32 *argv_orig = argv;
|
2005-07-17 10:18:23 +00:00
|
|
|
uint modifier = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
while ((b = *str++) != '\0') {
|
|
|
|
switch (b) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0x1: // {SETX}
|
|
|
|
*buff++ = b;
|
|
|
|
*buff++ = *str++;
|
|
|
|
break;
|
|
|
|
case 0x2: // {SETXY}
|
|
|
|
*buff++ = b;
|
|
|
|
*buff++ = *str++;
|
|
|
|
*buff++ = *str++;
|
|
|
|
break;
|
2005-09-10 15:14:35 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0x81: // {STRINL}
|
2006-02-03 21:51:42 +00:00
|
|
|
buff = GetStringWithArgs(buff, ReadLE16Unaligned(str), argv);
|
2004-08-09 17:04:08 +00:00
|
|
|
str += 2;
|
|
|
|
break;
|
|
|
|
case 0x82: // {DATE_LONG}
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = FormatYmdString(buff, GetInt32(&argv));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
case 0x83: // {DATE_SHORT}
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = FormatMonthAndYear(buff, GetInt32(&argv));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
case 0x84: {// {VELOCITY}
|
2006-03-26 21:50:57 +00:00
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
// 0x85 is used as escape character..
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0x85:
|
2005-02-06 11:23:41 +00:00
|
|
|
switch (*str++) {
|
2004-09-13 20:38:36 +00:00
|
|
|
case 0: /* {CURRCOMPACT} */
|
2005-09-27 20:55:42 +00:00
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-13 20:38:36 +00:00
|
|
|
case 2: /* {REV} */
|
2005-05-22 07:43:18 +00:00
|
|
|
buff = strecpy(buff, _openttd_revision, NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-13 20:38:36 +00:00
|
|
|
case 3: { /* {SHORTCARGO} */
|
|
|
|
// Short description of cargotypes. Layout:
|
2004-08-09 17:04:08 +00:00
|
|
|
// 8-bit = cargo type
|
|
|
|
// 16-bit = cargo count
|
2006-04-22 01:37:31 +00:00
|
|
|
StringID cargo_str = _cargo_types_base_values[_opt_ptr->landscape].units_volume[GetInt32(&argv)];
|
2006-03-26 21:50:57 +00:00
|
|
|
switch (cargo_str) {
|
|
|
|
case STR_TONS: {
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case STR_LITERS: {
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
buff = FormatCommaNumber(buff, GetInt32(&argv));
|
|
|
|
buff = strecpy(buff, " ", NULL);
|
|
|
|
buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
|
|
|
|
break;
|
|
|
|
}
|
2005-02-06 11:23:41 +00:00
|
|
|
} break;
|
2005-07-15 14:53:44 +00:00
|
|
|
case 4: {/* {CURRCOMPACT64} */
|
2004-09-13 20:38:36 +00:00
|
|
|
// 64 bit compact currency-unit
|
2005-09-27 20:55:42 +00:00
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
case 5: { /* {STRING1} */
|
|
|
|
// String that consumes ONE argument
|
2005-07-17 10:18:23 +00:00
|
|
|
uint str = modifier + GetInt32(&argv);
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1));
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2005-07-15 14:53:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6: { /* {STRING2} */
|
|
|
|
// String that consumes TWO arguments
|
2005-07-17 10:18:23 +00:00
|
|
|
uint str = modifier + GetInt32(&argv);
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2));
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2005-07-15 14:53:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7: { /* {STRING3} */
|
|
|
|
// String that consumes THREE arguments
|
2005-07-17 10:18:23 +00:00
|
|
|
uint str = modifier + GetInt32(&argv);
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3));
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2005-07-15 14:53:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 8: { /* {STRING4} */
|
|
|
|
// String that consumes FOUR arguments
|
2005-07-17 10:18:23 +00:00
|
|
|
uint str = modifier + GetInt32(&argv);
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4));
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2005-07-15 14:53:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 9: { /* {STRING5} */
|
|
|
|
// String that consumes FIVE arguments
|
2005-07-17 10:18:23 +00:00
|
|
|
uint str = modifier + GetInt32(&argv);
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5));
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2005-07-15 14:53:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-15 18:30:13 +00:00
|
|
|
case 10: { /* {STATIONFEATURES} */
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = StationGetSpecialString(buff, GetInt32(&argv));
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 18:30:13 +00:00
|
|
|
case 11: { /* {INDUSTRY} */
|
2006-02-18 14:41:24 +00:00
|
|
|
const Industry* i = GetIndustry(GetInt32(&argv));
|
2005-07-15 18:30:13 +00:00
|
|
|
int32 args[2];
|
|
|
|
|
|
|
|
// industry not valid anymore?
|
2006-08-22 15:33:35 +00:00
|
|
|
if (!IsValidIndustry(i)) break;
|
2005-07-15 18:30:13 +00:00
|
|
|
|
|
|
|
// First print the town name and the industry type name
|
|
|
|
// The string STR_INDUSTRY_PATTERN controls the formatting
|
|
|
|
args[0] = i->town->index;
|
|
|
|
args[1] = i->type + STR_4802_COAL_MINE;
|
2005-07-17 10:18:23 +00:00
|
|
|
buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
2005-07-15 18:30:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-16 20:58:04 +00:00
|
|
|
case 12: { // {VOLUME}
|
2006-03-26 21:50:57 +00:00
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24);
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2005-07-16 20:58:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 13: { // {G 0 Der Die Das}
|
2005-11-15 09:00:02 +00:00
|
|
|
const byte* s = (const byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
|
2005-07-16 20:58:04 +00:00
|
|
|
int len;
|
|
|
|
int gender = 0;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (s != NULL && s[0] == 0x87) gender = s[1];
|
2005-07-16 20:58:04 +00:00
|
|
|
str = ParseStringChoice(str, gender, buff, &len);
|
|
|
|
buff += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
case 14: { // {DATE_TINY}
|
|
|
|
buff = FormatTinyDate(buff, GetInt32(&argv));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 15: { // {CARGO}
|
|
|
|
// Layout now is:
|
|
|
|
// 8bit - cargo type
|
|
|
|
// 16-bit - cargo count
|
|
|
|
StringID cargo_str = _cargoc.names_long[GetInt32(&argv)];
|
2005-07-19 21:14:00 +00:00
|
|
|
buff = GetStringWithArgs(buff, cargo_str, argv++);
|
2005-07-17 10:18:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-26 21:50:57 +00:00
|
|
|
case 16: { // {POWER}
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 17: { // {VOLUME_S}
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 18: { // {WEIGHT}
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 19: { // {WEIGHT_S}
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-04-09 18:25:31 +00:00
|
|
|
case 20: { // {FORCE}
|
|
|
|
int32 args[1];
|
|
|
|
assert(_opt_ptr->units < lengthof(units));
|
|
|
|
args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s;
|
|
|
|
buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24);
|
|
|
|
modifier = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
default:
|
|
|
|
error("!invalid escape sequence in string");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x86: // {SKIP}
|
2005-07-15 14:53:44 +00:00
|
|
|
argv++;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-07-16 20:58:04 +00:00
|
|
|
|
|
|
|
// This sets up the gender for the string.
|
2005-07-17 10:18:23 +00:00
|
|
|
// We just ignore this one. It's used in {G 0 Der Die Das} to determine the case.
|
2005-07-16 20:58:04 +00:00
|
|
|
case 0x87: // {GENDER 0}
|
|
|
|
str++;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
case 0x88: {// {STRING}
|
2005-07-17 10:18:23 +00:00
|
|
|
uint str = modifier + GetInt32(&argv);
|
2005-07-15 14:53:44 +00:00
|
|
|
// WARNING. It's prohibited for the included string to consume any arguments.
|
|
|
|
// For included strings that consume argument, you should use STRING1, STRING2 etc.
|
|
|
|
// To debug stuff you can set argv to NULL and it will tell you
|
|
|
|
buff = GetStringWithArgs(buff, str, argv);
|
2005-07-17 10:18:23 +00:00
|
|
|
modifier = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-10 15:14:35 +00:00
|
|
|
case 0x8B: // {COMMA}
|
|
|
|
buff = FormatCommaNumber(buff, GetInt32(&argv));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x8C: // Move argument pointer
|
|
|
|
argv = argv_orig + (byte)*str++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x8D: { // {P}
|
|
|
|
int32 v = argv_orig[(byte)*str++]; // contains the number that determines plural
|
|
|
|
int len;
|
|
|
|
str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len);
|
|
|
|
buff += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x8E: // {NUM}
|
|
|
|
buff = FormatNoCommaNumber(buff, GetInt32(&argv));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x8F: // {CURRENCY}
|
2005-09-27 20:55:42 +00:00
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false);
|
2005-09-10 15:14:35 +00:00
|
|
|
break;
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
case 0x99: { // {WAYPOINT}
|
|
|
|
int32 temp[2];
|
|
|
|
Waypoint *wp = GetWaypoint(GetInt32(&argv));
|
|
|
|
StringID str;
|
|
|
|
if (wp->string != STR_NULL) {
|
|
|
|
str = wp->string;
|
|
|
|
} else {
|
|
|
|
temp[0] = wp->town_index;
|
|
|
|
temp[1] = wp->town_cn + 1;
|
|
|
|
str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL;
|
|
|
|
}
|
|
|
|
buff = GetStringWithArgs(buff, str, temp);
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case 0x9A: { // {STATION}
|
2005-11-13 13:43:55 +00:00
|
|
|
const Station* st = GetStation(GetInt32(&argv));
|
2005-07-15 14:53:44 +00:00
|
|
|
int32 temp[2];
|
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
if (!IsValidStation(st)) { // station doesn't exist anymore
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL);
|
2004-08-16 13:54:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
temp[0] = st->town->townnametype;
|
|
|
|
temp[1] = st->town->townnameparts;
|
|
|
|
buff = GetStringWithArgs(buff, st->string_id, temp);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x9B: { // {TOWN}
|
2005-11-13 13:43:55 +00:00
|
|
|
const Town* t = GetTown(GetInt32(&argv));
|
2005-07-15 14:53:44 +00:00
|
|
|
int32 temp[1];
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
assert(IsValidTown(t));
|
2005-11-13 13:43:55 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
temp[0] = t->townnameparts;
|
|
|
|
buff = GetStringWithArgs(buff, t->townnametype, temp);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x9C: { // {CURRENCY64}
|
2005-09-27 20:55:42 +00:00
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
case 0x9D: { // {SETCASE}
|
2005-11-14 19:48:04 +00:00
|
|
|
// This is a pseudo command, it's outputted when someone does {STRING.ack}
|
2005-07-17 10:18:23 +00:00
|
|
|
// The modifier is added to all subsequent GetStringWithArgs that accept the modifier.
|
|
|
|
modifier = (byte)*str++ << 24;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-22 23:13:20 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
case 0x9E: { // {Used to implement case switching}
|
|
|
|
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
|
|
|
|
// Each LEN is printed using 2 bytes in big endian order.
|
|
|
|
uint num = (byte)*str++;
|
|
|
|
while (num) {
|
2005-07-17 18:11:17 +00:00
|
|
|
if ((byte)str[0] == casei) {
|
2005-07-17 10:18:23 +00:00
|
|
|
// Found the case, adjust str pointer and continue
|
|
|
|
str += 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Otherwise skip to the next case
|
|
|
|
str += 3 + (str[1] << 8) + str[2];
|
|
|
|
num--;
|
|
|
|
}
|
2005-01-22 23:13:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
default:
|
|
|
|
*buff++ = b;
|
|
|
|
}
|
|
|
|
}
|
2005-02-06 11:23:41 +00:00
|
|
|
*buff = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static char *StationGetSpecialString(char *buff, int x)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-08-20 18:14:32 +00:00
|
|
|
if (x & 0x01) *buff++ = '\x94';
|
|
|
|
if (x & 0x02) *buff++ = '\x95';
|
|
|
|
if (x & 0x04) *buff++ = '\x96';
|
|
|
|
if (x & 0x08) *buff++ = '\x97';
|
|
|
|
if (x & 0x10) *buff++ = '\x98';
|
2005-02-06 11:23:41 +00:00
|
|
|
*buff = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed)
|
2005-02-06 11:23:41 +00:00
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
_town_name_generators[ind](buff, seed);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
while (*buff != '\0') buff++;
|
2004-08-09 17:04:08 +00:00
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-11-16 11:17:52 +00:00
|
|
|
static const char* const _silly_company_names[] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
"Bloggs Brothers",
|
|
|
|
"Tiny Transport Ltd.",
|
|
|
|
"Express Travel",
|
|
|
|
"Comfy-Coach & Co.",
|
|
|
|
"Crush & Bump Ltd.",
|
|
|
|
"Broken & Late Ltd.",
|
|
|
|
"Sam Speedy & Son",
|
|
|
|
"Supersonic Travel",
|
|
|
|
"Mike's Motors",
|
|
|
|
"Lightning International",
|
|
|
|
"Pannik & Loozit Ltd.",
|
|
|
|
"Inter-City Transport",
|
2005-11-16 11:17:52 +00:00
|
|
|
"Getout & Pushit Ltd."
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-11-16 11:17:52 +00:00
|
|
|
static const char* const _surname_list[] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
"Adams",
|
|
|
|
"Allan",
|
|
|
|
"Baker",
|
|
|
|
"Bigwig",
|
|
|
|
"Black",
|
|
|
|
"Bloggs",
|
|
|
|
"Brown",
|
|
|
|
"Campbell",
|
|
|
|
"Gordon",
|
|
|
|
"Hamilton",
|
|
|
|
"Hawthorn",
|
|
|
|
"Higgins",
|
|
|
|
"Green",
|
|
|
|
"Gribble",
|
|
|
|
"Jones",
|
|
|
|
"McAlpine",
|
|
|
|
"MacDonald",
|
|
|
|
"McIntosh",
|
|
|
|
"Muir",
|
|
|
|
"Murphy",
|
|
|
|
"Nelson",
|
|
|
|
"O'Donnell",
|
|
|
|
"Parker",
|
|
|
|
"Phillips",
|
|
|
|
"Pilkington",
|
|
|
|
"Quigley",
|
|
|
|
"Sharkey",
|
|
|
|
"Thomson",
|
2005-11-16 11:17:52 +00:00
|
|
|
"Watkins"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const _silly_surname_list[] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
"Grumpy",
|
|
|
|
"Dozy",
|
|
|
|
"Speedy",
|
|
|
|
"Nosey",
|
|
|
|
"Dribble",
|
|
|
|
"Mushroom",
|
|
|
|
"Cabbage",
|
|
|
|
"Sniffle",
|
|
|
|
"Fishy",
|
|
|
|
"Swindle",
|
|
|
|
"Sneaky",
|
2005-11-16 11:17:52 +00:00
|
|
|
"Nutkins"
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static const char _initial_name_letters[] = {
|
2005-02-06 16:56:04 +00:00
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
|
|
|
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W',
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static char *GenAndCoName(char *buff, uint32 arg)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-16 11:17:52 +00:00
|
|
|
const char* const* base;
|
|
|
|
uint num;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-16 16:16:54 +00:00
|
|
|
if (_opt_ptr->landscape == LT_CANDY) {
|
2005-11-16 11:17:52 +00:00
|
|
|
base = _silly_surname_list;
|
|
|
|
num = lengthof(_silly_surname_list);
|
|
|
|
} else {
|
|
|
|
base = _surname_list;
|
|
|
|
num = lengthof(_surname_list);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 11:17:52 +00:00
|
|
|
buff = strecpy(buff, base[num * GB(arg, 16, 8) >> 8], NULL);
|
2005-05-22 07:43:18 +00:00
|
|
|
buff = strecpy(buff, " & Co.", NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static char *GenPresidentName(char *buff, uint32 x)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-16 11:17:52 +00:00
|
|
|
const char* const* base;
|
|
|
|
uint num;
|
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-21 06:31:02 +00:00
|
|
|
buff[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8];
|
2004-08-09 17:04:08 +00:00
|
|
|
buff[1] = '.';
|
2004-09-13 12:28:11 +00:00
|
|
|
buff[2] = ' '; // Insert a space after initial and period "I. Firstname" instead of "I.Firstname"
|
|
|
|
buff += 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-21 06:31:02 +00:00
|
|
|
i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (i < sizeof(_initial_name_letters)) {
|
|
|
|
buff[0] = _initial_name_letters[i];
|
|
|
|
buff[1] = '.';
|
2004-09-13 12:28:11 +00:00
|
|
|
buff[2] = ' '; // Insert a space after initial and period "I. J. Firstname" instead of "I.J.Firstname"
|
|
|
|
buff += 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:16:54 +00:00
|
|
|
if (_opt_ptr->landscape == LT_CANDY) {
|
2005-11-16 11:17:52 +00:00
|
|
|
base = _silly_surname_list;
|
|
|
|
num = lengthof(_silly_surname_list);
|
|
|
|
} else {
|
|
|
|
base = _surname_list;
|
|
|
|
num = lengthof(_surname_list);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 11:17:52 +00:00
|
|
|
buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-06 11:23:41 +00:00
|
|
|
switch (ind) {
|
2005-02-06 16:56:04 +00:00
|
|
|
case 1: // not used
|
2005-07-15 14:53:44 +00:00
|
|
|
return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 2: // used for Foobar & Co company names
|
2005-07-15 14:53:44 +00:00
|
|
|
return GenAndCoName(buff, GetInt32(&argv));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 3: // President name
|
2005-07-15 14:53:44 +00:00
|
|
|
return GenPresidentName(buff, GetInt32(&argv));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 4: // song names
|
2006-07-07 02:44:51 +00:00
|
|
|
return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// town name?
|
2005-02-06 11:23:41 +00:00
|
|
|
if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
|
2005-07-15 14:53:44 +00:00
|
|
|
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv));
|
2005-05-22 07:43:18 +00:00
|
|
|
return strecpy(buff, " Transport", NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// language name?
|
|
|
|
if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
|
|
|
|
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
|
2005-05-22 07:43:18 +00:00
|
|
|
return strecpy(buff,
|
|
|
|
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resolution size?
|
|
|
|
if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
|
|
|
|
int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
|
|
|
|
return buff + sprintf(buff, "%dx%d", _resolutions[i][0], _resolutions[i][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// screenshot format name?
|
|
|
|
if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
|
|
|
|
int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
|
2005-05-22 07:43:18 +00:00
|
|
|
return strecpy(buff, GetScreenshotFormatDesc(i), NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remap a string ID from the old format to the new format
|
|
|
|
StringID RemapOldStringID(StringID s)
|
|
|
|
{
|
2005-02-06 16:56:04 +00:00
|
|
|
switch (s) {
|
|
|
|
case 0x0006: return STR_SV_EMPTY;
|
|
|
|
case 0x7000: return STR_SV_UNNAMED;
|
|
|
|
case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH;
|
|
|
|
case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH;
|
|
|
|
case 0x8864: return STR_SV_TRAIN_NAME;
|
|
|
|
case 0x902B: return STR_SV_ROADVEH_NAME;
|
|
|
|
case 0x9830: return STR_SV_SHIP_NAME;
|
|
|
|
case 0xA02F: return STR_SV_AIRCRAFT_NAME;
|
|
|
|
|
|
|
|
default:
|
2006-02-01 06:32:03 +00:00
|
|
|
if (IS_INT_INSIDE(s, 0x300F, 0x3030)) {
|
2005-02-06 16:56:04 +00:00
|
|
|
return s - 0x300F + STR_SV_STNAME;
|
2006-02-01 06:32:03 +00:00
|
|
|
} else {
|
2005-02-06 16:56:04 +00:00
|
|
|
return s;
|
2006-02-01 06:32:03 +00:00
|
|
|
}
|
2005-02-06 16:56:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
bool ReadLanguagePack(int lang_index)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
int tot_count, i;
|
2005-02-06 14:47:56 +00:00
|
|
|
LanguagePack *lang_pack;
|
2004-08-09 17:04:08 +00:00
|
|
|
size_t len;
|
2005-02-06 09:52:06 +00:00
|
|
|
char **langpack_offs;
|
|
|
|
char *s;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file);
|
|
|
|
lang_pack = ReadFileToMem(lang, &len, 100000);
|
|
|
|
free(lang);
|
|
|
|
}
|
|
|
|
if (lang_pack == NULL) return false;
|
2005-02-06 14:47:56 +00:00
|
|
|
if (len < sizeof(LanguagePack) ||
|
|
|
|
lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
|
|
|
|
lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
free(lang_pack);
|
|
|
|
return false;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#if defined(TTD_BIG_ENDIAN)
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != 32; i++) {
|
2006-02-03 21:51:42 +00:00
|
|
|
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tot_count = 0;
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != 32; i++) {
|
2005-02-06 14:47:56 +00:00
|
|
|
uint num = lang_pack->offsets[i];
|
2004-08-09 17:04:08 +00:00
|
|
|
_langtab_start[i] = tot_count;
|
|
|
|
_langtab_num[i] = num;
|
|
|
|
tot_count += num;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate offsets
|
2005-02-06 09:52:06 +00:00
|
|
|
langpack_offs = malloc(tot_count * sizeof(*langpack_offs));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Fill offsets
|
2005-02-06 14:47:56 +00:00
|
|
|
s = lang_pack->data;
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != tot_count; i++) {
|
2005-02-06 09:52:06 +00:00
|
|
|
len = (byte)*s;
|
2005-02-06 11:23:41 +00:00
|
|
|
*s++ = '\0'; // zero terminate the string before.
|
|
|
|
if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++;
|
2004-08-09 17:04:08 +00:00
|
|
|
langpack_offs[i] = s;
|
|
|
|
s += len;
|
|
|
|
}
|
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
free(_langpack);
|
2004-08-09 17:04:08 +00:00
|
|
|
_langpack = lang_pack;
|
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
free(_langpack_offs);
|
2004-08-09 17:04:08 +00:00
|
|
|
_langpack_offs = langpack_offs;
|
|
|
|
|
|
|
|
ttd_strlcpy(_dynlang.curr_file, _dynlang.ent[lang_index].file, sizeof(_dynlang.curr_file));
|
|
|
|
|
|
|
|
_dynlang.curr = lang_index;
|
2006-04-21 03:00:20 +00:00
|
|
|
SetCurrentGrfLangID(_langpack->isocode);
|
2004-08-09 17:04:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-25 09:22:10 +00:00
|
|
|
/** Determine the current charset based on the environment
|
|
|
|
* First check some default values, after this one we passed ourselves
|
|
|
|
* and if none exist return the value for $LANG
|
|
|
|
* @param environment variable to check conditionally if default ones are not
|
|
|
|
* set. Pass NULL if you don't want additional checks.
|
|
|
|
* @return return string containing current charset, or NULL if not-determinable */
|
|
|
|
const char *GetCurrentLocale(const char *param)
|
|
|
|
{
|
|
|
|
const char *env;
|
|
|
|
|
|
|
|
env = getenv("LANGUAGE");
|
|
|
|
if (env != NULL) return env;
|
|
|
|
|
|
|
|
env = getenv("LC_ALL");
|
|
|
|
if (env != NULL) return env;
|
|
|
|
|
|
|
|
if (param != NULL) {
|
|
|
|
env = getenv(param);
|
|
|
|
if (env != NULL) return env;
|
|
|
|
}
|
|
|
|
|
|
|
|
return getenv("LANG");
|
|
|
|
}
|
|
|
|
|
2006-08-04 23:45:20 +00:00
|
|
|
static int CDECL LanguageCompareFunc(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return strcmp(*(const char* const *)a, *(const char* const *)b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int GetLanguageList(char **languages, int max)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
dir = opendir(_path.lang_dir);
|
|
|
|
if (dir != NULL) {
|
|
|
|
while ((dirent = readdir(dir)) != NULL) {
|
|
|
|
char *t = strrchr(dirent->d_name, '.');
|
|
|
|
|
|
|
|
if (t != NULL && strcmp(t, ".lng") == 0) {
|
|
|
|
languages[num++] = strdup(dirent->d_name);
|
|
|
|
if (num == max) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(languages, num, sizeof(char*), LanguageCompareFunc);
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// make a list of the available language packs. put the data in _dynlang struct.
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeLanguagePacks(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
DynamicLanguages *dl = &_dynlang;
|
2005-02-06 16:56:04 +00:00
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
int m;
|
|
|
|
int def;
|
2005-08-01 01:12:21 +00:00
|
|
|
int fallback;
|
2005-02-06 14:47:56 +00:00
|
|
|
LanguagePack hdr;
|
2004-08-09 17:04:08 +00:00
|
|
|
FILE *in;
|
|
|
|
char *files[32];
|
2005-08-01 01:12:21 +00:00
|
|
|
|
|
|
|
char lang[] = "en";
|
2006-03-25 09:22:10 +00:00
|
|
|
const char *env = GetCurrentLocale("LC_MESSAGES");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-25 09:22:10 +00:00
|
|
|
if (env != NULL) snprintf(lang, lengthof(lang), "%.2s", env);
|
2004-08-09 17:04:08 +00:00
|
|
|
n = GetLanguageList(files, lengthof(files));
|
|
|
|
|
2005-08-01 01:12:21 +00:00
|
|
|
def = -1;
|
|
|
|
fallback = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// go through the language files and make sure that they are valid.
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = m = 0; i != n; i++) {
|
2006-08-20 12:09:32 +00:00
|
|
|
size_t j;
|
2005-02-06 16:56:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
char *s = str_fmt("%s%s", _path.lang_dir, files[i]);
|
|
|
|
in = fopen(s, "rb");
|
|
|
|
free(s);
|
2005-02-06 11:23:41 +00:00
|
|
|
if (in == NULL ||
|
2004-08-09 17:04:08 +00:00
|
|
|
(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 ||
|
|
|
|
hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
|
|
|
|
hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) {
|
|
|
|
free(files[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dl->ent[m].file = files[i];
|
|
|
|
dl->ent[m].name = strdup(hdr.name);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-08-01 01:12:21 +00:00
|
|
|
if (strcmp(hdr.name, "English") == 0) fallback = m;
|
|
|
|
if (strcmp(hdr.isocode, lang) == 0) def = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
m++;
|
|
|
|
}
|
2005-08-01 01:12:21 +00:00
|
|
|
if (def == -1) def = fallback;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (m == 0)
|
|
|
|
error(n == 0 ? "No available language packs" : "Invalid version of language packs");
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
dl->num = m;
|
2006-02-18 14:41:24 +00:00
|
|
|
for (i = 0; i != dl->num; i++) dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
|
2004-08-09 17:04:08 +00:00
|
|
|
dl->dropdown[i] = INVALID_STRING_ID;
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != dl->num; i++)
|
|
|
|
if (strcmp(dl->ent[i].file, dl->curr_file) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
def = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ReadLanguagePack(def))
|
|
|
|
error("can't read language pack '%s'", dl->ent[def].file);
|
2005-07-15 21:28:26 +00:00
|
|
|
}
|