2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.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"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *StationGetSpecialString(char *buff);
|
|
|
|
static char *GetSpecialTownNameString(char *buff, int ind);
|
|
|
|
static char *GetSpecialPlayerNameString(char *buff, int ind);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *DecodeString(char *buff, const char *str);
|
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;
|
|
|
|
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
|
2005-02-17 07:49:31 +00:00
|
|
|
char isocode[16]; // the ISO code for the language (not country code)
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 offsets[32]; // the offsets
|
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
|
|
|
const StringID _currency_string_list[] = {
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_GBP,
|
|
|
|
STR_CURR_USD,
|
|
|
|
STR_CURR_EUR,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_CURR_YEN,
|
|
|
|
STR_CURR_ATS,
|
|
|
|
STR_CURR_BEF,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_CHF,
|
|
|
|
STR_CURR_CZK,
|
|
|
|
STR_CURR_DEM,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_CURR_DKK,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_ESP,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_CURR_FIM,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_FRF,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_CURR_GRD,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_HUF,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_CURR_ISK,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_ITL,
|
|
|
|
STR_CURR_NLG,
|
2004-08-09 17:04:08 +00:00
|
|
|
STR_CURR_NOK,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_PLN,
|
2004-09-15 22:32:37 +00:00
|
|
|
STR_CURR_ROL,
|
2004-12-22 16:54:55 +00:00
|
|
|
STR_CURR_RUR,
|
|
|
|
STR_CURR_SEK,
|
2004-12-22 13:19:26 +00:00
|
|
|
STR_CURR_CUSTOM,
|
2004-08-09 17:04:08 +00:00
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
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-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-02-06 16:56:04 +00:00
|
|
|
char *GetString(char *buffr, StringID string)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint index = string & 0x7FF;
|
|
|
|
uint tab = string >> 11;
|
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
switch (string) {
|
|
|
|
case 0:
|
|
|
|
error("!invalid string id 0 in GetString");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x30D1:
|
|
|
|
return StationGetSpecialString(buffr);
|
|
|
|
|
|
|
|
case STR_SPEC_SCREENSHOT_NAME:
|
|
|
|
return DecodeString(buffr, _screenshot_name);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
switch (tab) {
|
|
|
|
case 4:
|
|
|
|
if (index >= 0xC0) return GetSpecialTownNameString(buffr, index - 0xC0);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 14:
|
|
|
|
if (index >= 0xE4) return GetSpecialPlayerNameString(buffr, index - 0xE4);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 15:
|
|
|
|
return GetName(index, buffr);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 31: // special or dynamic strings
|
|
|
|
return DecodeString(buffr, _userstring);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 17:04:08 +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
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return DecodeString(buffr, GetStringPtr(string));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
int32 GetParamInt32(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-02 22:53:07 +00:00
|
|
|
int32 result = GetDParam(0);
|
2004-11-15 10:31:48 +00:00
|
|
|
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
|
2004-08-09 17:04:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static int64 GetParamInt64(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-02 22:53:07 +00:00
|
|
|
int64 result = GetDParam(0) + ((uint64)GetDParam(1) << 32);
|
2004-11-15 10:31:48 +00:00
|
|
|
memmove(&_decode_parameters[0], &_decode_parameters[2], sizeof(uint32) * (lengthof(_decode_parameters)-2));
|
2004-08-09 17:04:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
int GetParamInt16(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-02 22:53:07 +00:00
|
|
|
int result = (int16)GetDParam(0);
|
2004-11-15 10:31:48 +00:00
|
|
|
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
|
2004-08-09 17:04:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
int GetParamInt8(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-02 22:53:07 +00:00
|
|
|
int result = (int8)GetDParam(0);
|
2004-11-15 10:31:48 +00:00
|
|
|
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
|
2004-08-09 17:04:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
int GetParamUint16(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-02 22:53:07 +00:00
|
|
|
int result = GetDParam(0);
|
2004-11-15 10:31:48 +00:00
|
|
|
memmove(&_decode_parameters[0], &_decode_parameters[1], sizeof(uint32) * (lengthof(_decode_parameters)-1));
|
2004-08-09 17:04:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *FormatYmdString(char *buff, uint16 number)
|
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;
|
|
|
|
|
|
|
|
ConvertDayToYMD(&ymd, number);
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
for (src = GetStringPtr(ymd.day + STR_01AC_1ST - 1); (*buff++ = *src++) != '\0';) {}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
buff[-1] = ' ';
|
|
|
|
memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
|
|
|
|
buff[3] = ' ';
|
|
|
|
|
2005-01-10 14:43:00 +00:00
|
|
|
return FormatNoCommaNumber(buff+4, ymd.year + MAX_YEAR_BEGIN_REAL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *FormatMonthAndYear(char *buff, uint16 number)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const char *src;
|
|
|
|
YearMonthDay ymd;
|
|
|
|
|
|
|
|
ConvertDayToYMD(&ymd, number);
|
|
|
|
|
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] = ' ';
|
|
|
|
|
2005-01-10 14:43:00 +00:00
|
|
|
return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *FormatTinyDate(char *buff, uint16 number)
|
2005-01-22 23:13:20 +00:00
|
|
|
{
|
|
|
|
YearMonthDay ymd;
|
|
|
|
|
|
|
|
ConvertDayToYMD(&ymd, number);
|
|
|
|
buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL);
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
uint GetCurrentCurrencyRate(void)
|
|
|
|
{
|
2005-04-16 16:16:54 +00:00
|
|
|
return _currency_specs[_opt_ptr->currency].rate;
|
2004-08-12 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2004-12-23 18:28:13 +00:00
|
|
|
// add prefix part
|
|
|
|
s = spec->prefix;
|
2005-02-06 11:23:41 +00:00
|
|
|
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;
|
|
|
|
|
2004-12-23 18:28:13 +00:00
|
|
|
// add suffix part
|
|
|
|
s = spec->suffix;
|
2005-02-06 11:23:41 +00:00
|
|
|
while (s != spec->suffix + lengthof(spec->suffix) && (c = *s++) != '\0') *buff++ = c;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *DecodeString(char *buff, const char *str)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte b;
|
|
|
|
|
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;
|
|
|
|
case 0x7B: // {COMMA32}
|
|
|
|
buff = FormatCommaNumber(buff, GetParamInt32());
|
|
|
|
break;
|
|
|
|
case 0x7C: // {COMMA16}
|
|
|
|
buff = FormatCommaNumber(buff, GetParamInt16());
|
|
|
|
break;
|
|
|
|
case 0x7D: // {COMMA8}
|
|
|
|
buff = FormatCommaNumber(buff, GetParamInt8());
|
|
|
|
break;
|
|
|
|
case 0x7E: // {NUMU16}
|
|
|
|
buff = FormatNoCommaNumber(buff, GetParamInt16());
|
|
|
|
break;
|
|
|
|
case 0x7F: // {CURRENCY}
|
2005-04-16 16:16:54 +00:00
|
|
|
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt32(), false);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
// 0x80 is reserved for EURO
|
|
|
|
case 0x81: // {STRINL}
|
|
|
|
str += 2;
|
|
|
|
buff = GetString(buff, READ_LE_UINT16(str-2));
|
|
|
|
break;
|
|
|
|
case 0x82: // {DATE_LONG}
|
|
|
|
buff = FormatYmdString(buff, GetParamUint16());
|
|
|
|
break;
|
|
|
|
case 0x83: // {DATE_SHORT}
|
|
|
|
buff = FormatMonthAndYear(buff, GetParamUint16());
|
|
|
|
break;
|
|
|
|
case 0x84: {// {VELOCITY}
|
|
|
|
int value = GetParamInt16();
|
2005-04-16 16:16:54 +00:00
|
|
|
if (_opt_ptr->kilometers) value = value * 1648 >> 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = FormatCommaNumber(buff, value);
|
2005-04-16 16:16:54 +00:00
|
|
|
if (_opt_ptr->kilometers) {
|
2004-08-09 17:04:08 +00:00
|
|
|
memcpy(buff, " km/h", 5);
|
|
|
|
buff += 5;
|
|
|
|
} else {
|
|
|
|
memcpy(buff, " mph", 4);
|
|
|
|
buff += 4;
|
|
|
|
}
|
|
|
|
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-04-16 16:16:54 +00:00
|
|
|
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt32(), true);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-13 20:38:36 +00:00
|
|
|
case 1: /* {INT32} */
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = FormatNoCommaNumber(buff, GetParamInt32());
|
|
|
|
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
|
2005-04-16 16:16:54 +00:00
|
|
|
StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][(byte)GetParamInt8()];
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
|
|
|
|
// liquid type of cargo is multiplied by 100 to get correct amount
|
2005-02-06 11:23:41 +00:00
|
|
|
buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
|
2005-05-22 07:43:18 +00:00
|
|
|
buff = strecpy(buff, " ", NULL);
|
|
|
|
buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
|
2005-02-06 11:23:41 +00:00
|
|
|
} break;
|
2004-09-13 20:38:36 +00:00
|
|
|
case 4: /* {CURRCOMPACT64} */
|
|
|
|
// 64 bit compact currency-unit
|
2005-04-16 16:16:54 +00:00
|
|
|
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt64(), true);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error("!invalid escape sequence in string");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x86: // {SKIP}
|
|
|
|
GetParamInt16();
|
|
|
|
//assert(0);
|
|
|
|
break;
|
2005-05-22 07:43:18 +00:00
|
|
|
case 0x87: // {VOLUME}
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = FormatCommaNumber(buff, GetParamInt16() * 1000);
|
2005-05-22 07:43:18 +00:00
|
|
|
buff = strecpy(buff, " ", NULL);
|
|
|
|
buff = strecpy(buff, GetStringPtr(STR_LITERS), NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case 0x88: // {STRING}
|
|
|
|
buff = GetString(buff, (uint16)GetParamUint16());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x99: { // {CARGO}
|
|
|
|
// Layout now is:
|
|
|
|
// 8bit - cargo type
|
|
|
|
// 16-bit - cargo count
|
|
|
|
int cargo_str = _cargoc.names_long_s[GetParamInt8()];
|
|
|
|
// Now check if the cargo count is 1, if it is, increase string by 32.
|
2004-12-02 22:53:07 +00:00
|
|
|
if (GetDParam(0) != 1) cargo_str += 32;
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = GetString(buff, cargo_str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x9A: { // {STATION}
|
|
|
|
Station *st;
|
2005-02-06 08:18:00 +00:00
|
|
|
InjectDParam(1);
|
2005-01-06 22:31:58 +00:00
|
|
|
st = GetStation(GetDParam(1));
|
2005-02-06 11:23:41 +00:00
|
|
|
if (st->xy == 0) { // station doesn't exist anymore
|
2004-08-16 13:54:37 +00:00
|
|
|
buff = GetString(buff, STR_UNKNOWN_DESTINATION);
|
|
|
|
break;
|
|
|
|
}
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, st->town->townnametype);
|
|
|
|
SetDParam(1, st->town->townnameparts);
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = GetString(buff, st->string_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0x9B: { // {TOWN}
|
|
|
|
Town *t;
|
2005-01-06 22:31:58 +00:00
|
|
|
t = GetTown(GetDParam(0));
|
2004-08-09 17:04:08 +00:00
|
|
|
assert(t->xy);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, t->townnameparts);
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = GetString(buff, t->townnametype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x9C: { // {CURRENCY64}
|
2005-04-16 16:16:54 +00:00
|
|
|
buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt64(), false);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-11-14 13:07:07 +00:00
|
|
|
case 0x9D: { // {WAYPOINT}
|
2005-03-24 17:03:37 +00:00
|
|
|
Waypoint *wp = GetWaypoint(GetDParam(0));
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
|
|
|
int idx;
|
2005-03-24 17:03:37 +00:00
|
|
|
if (wp->string != STR_NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
GetParamInt32(); // skip it
|
2005-03-24 17:03:37 +00:00
|
|
|
str = wp->string;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-03-24 17:03:37 +00:00
|
|
|
idx = wp->town_cn;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (idx == 0) {
|
2004-11-14 13:07:07 +00:00
|
|
|
str = STR_WAYPOINTNAME_CITY;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-02-06 08:18:00 +00:00
|
|
|
InjectDParam(1);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, idx + 1);
|
2004-11-14 13:07:07 +00:00
|
|
|
str = STR_WAYPOINTNAME_CITY_SERIAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-03-24 17:03:37 +00:00
|
|
|
SetDParam(0, wp->town_index);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buff = GetString(buff, str);
|
|
|
|
} break;
|
2005-01-22 23:13:20 +00:00
|
|
|
|
|
|
|
case 0x9E: { // {DATE_TINY}
|
|
|
|
buff = FormatTinyDate(buff, GetParamUint16());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// case 0x88..0x98: // {COLORS}
|
|
|
|
// case 0xE: // {TINYFONT}
|
|
|
|
// case 0xF: // {BIGFONT}
|
|
|
|
// 0x9E is the highest number that is available.
|
|
|
|
default:
|
|
|
|
*buff++ = b;
|
|
|
|
}
|
|
|
|
}
|
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 *StationGetSpecialString(char *buff)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int x = GetParamInt8();
|
2005-02-06 11:23:41 +00:00
|
|
|
if (x & 0x01) *buff++ = '\xB4';
|
|
|
|
if (x & 0x02) *buff++ = '\xB5';
|
|
|
|
if (x & 0x04) *buff++ = '\xB6';
|
|
|
|
if (x & 0x08) *buff++ = '\xB7';
|
|
|
|
if (x & 0x10) *buff++ = '\xB8';
|
|
|
|
*buff = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
static char *GetSpecialTownNameString(char *buff, int ind)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 x = GetParamInt32();
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_town_name_generators[ind](buff, x);
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
while (*buff != '\0') buff++;
|
2004-08-09 17:04:08 +00:00
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const _silly_company_names[] = {
|
|
|
|
"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",
|
|
|
|
"Getout & Pushit Ltd.",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const _surname_list[] = {
|
|
|
|
"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",
|
|
|
|
"Watkins",
|
|
|
|
"Grumpy",
|
|
|
|
"Dozy",
|
|
|
|
"Speedy",
|
|
|
|
"Nosey",
|
|
|
|
"Dribble",
|
|
|
|
"Mushroom",
|
|
|
|
"Cabbage",
|
|
|
|
"Sniffle",
|
|
|
|
"Fishy",
|
|
|
|
"Swindle",
|
|
|
|
"Sneaky",
|
|
|
|
"Nutkins",
|
|
|
|
};
|
|
|
|
|
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-02-06 09:52:06 +00:00
|
|
|
static char *GenAndCoName(char *buff)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint32 x = GetParamInt32();
|
|
|
|
uint base,num;
|
|
|
|
|
|
|
|
base = 0;
|
|
|
|
num = 29;
|
2005-04-16 16:16:54 +00:00
|
|
|
if (_opt_ptr->landscape == LT_CANDY) {
|
2004-08-09 17:04:08 +00:00
|
|
|
base = num;
|
|
|
|
num = 12;
|
|
|
|
}
|
|
|
|
|
2005-05-22 07:43:18 +00:00
|
|
|
buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL);
|
|
|
|
buff = strecpy(buff, " & Co.", NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *GenPlayerName_4(char *buff)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint32 x = GetParamInt32();
|
|
|
|
uint i, base, num;
|
|
|
|
|
2005-02-06 11:23:41 +00:00
|
|
|
buff[0] = _initial_name_letters[(sizeof(_initial_name_letters) * (byte)x) >> 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
|
|
|
|
|
|
|
i = ((sizeof(_initial_name_letters) + 35) * (byte)(x >> 8)) >> 8;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
base = 0;
|
|
|
|
num = 29;
|
2005-04-16 16:16:54 +00:00
|
|
|
if (_opt_ptr->landscape == LT_CANDY) {
|
2004-08-09 17:04:08 +00:00
|
|
|
base = num;
|
|
|
|
num = 12;
|
|
|
|
}
|
|
|
|
|
2005-05-22 07:43:18 +00:00
|
|
|
buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const _song_names[] = {
|
|
|
|
"Tycoon DELUXE Theme",
|
|
|
|
"Easy Driver",
|
|
|
|
"Little Red Diesel",
|
|
|
|
"Cruise Control",
|
|
|
|
"Don't Walk!",
|
|
|
|
"Fell Apart On Me",
|
|
|
|
"City Groove",
|
|
|
|
"Funk Central",
|
|
|
|
"Stoke It",
|
|
|
|
"Road Hog",
|
|
|
|
"Aliens Ate My Railway",
|
|
|
|
"Snarl Up",
|
|
|
|
"Stroll On",
|
|
|
|
"Can't Get There From Here",
|
|
|
|
"Sawyer's Tune",
|
|
|
|
"Hold That Train!",
|
|
|
|
"Movin' On",
|
|
|
|
"Goss Groove",
|
|
|
|
"Small Town",
|
|
|
|
"Broomer's Oil Rag",
|
|
|
|
"Jammit",
|
|
|
|
"Hard Drivin'"
|
|
|
|
};
|
|
|
|
|
2005-02-06 09:52:06 +00:00
|
|
|
static char *GetSpecialPlayerNameString(char *buff, int ind)
|
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-05-22 07:43:18 +00:00
|
|
|
return strecpy(buff, _silly_company_names[GetParamInt32() & 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
|
|
|
|
return GenAndCoName(buff);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 3: // President name
|
|
|
|
return GenPlayerName_4(buff);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 16:56:04 +00:00
|
|
|
case 4: // song names
|
2005-05-22 07:43:18 +00:00
|
|
|
return strecpy(buff, _song_names[GetParamUint16() - 1], 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)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
buff = GetSpecialTownNameString(buff, ind - 6);
|
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:
|
|
|
|
if (IS_INT_INSIDE(s, 0x300F, 0x3030))
|
|
|
|
return s - 0x300F + STR_SV_STNAME;
|
|
|
|
else
|
|
|
|
return s;
|
|
|
|
}
|
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++) {
|
2005-02-06 14:47:56 +00:00
|
|
|
lang_pack->offsets[i] = READ_LE_UINT16(&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;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-02-06 14:47:56 +00:00
|
|
|
LanguagePack hdr;
|
2004-08-09 17:04:08 +00:00
|
|
|
FILE *in;
|
|
|
|
char *files[32];
|
|
|
|
|
|
|
|
n = GetLanguageList(files, lengthof(files));
|
|
|
|
|
|
|
|
def = 0; // default language file
|
|
|
|
|
|
|
|
// 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++) {
|
2005-02-06 16:56:04 +00:00
|
|
|
int j;
|
|
|
|
|
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-02-06 11:23:41 +00:00
|
|
|
if (strcmp(hdr.name, "English") == 0) def = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2005-02-06 11:23:41 +00:00
|
|
|
for (i = 0; i != dl->num; i++)
|
2004-08-09 17:04:08 +00:00
|
|
|
dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
|
|
|
|
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);
|
|
|
|
}
|