|
@@ -123,56 +123,56 @@ void CopyOutDParam(uint64 *dst, const ch
|
|
|
static char *StationGetSpecialString(char *buff, int x, const char *last);
|
|
|
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
|
|
|
static char *GetSpecialNameString(char *buff, int ind, StringParameters *args, const char *last);
|
|
|
|
|
|
static char *FormatString(char *buff, const char *str, StringParameters *args, const char *last, uint case_index = 0, bool dry_run = false);
|
|
|
|
|
|
struct LanguagePack : public LanguagePackHeader {
|
|
|
char data[]; // list of strings
|
|
|
};
|
|
|
|
|
|
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
|
|
|
static uint _langtab_num[TAB_COUNT]; ///< Offset into langpack offs
|
|
|
static uint _langtab_start[TAB_COUNT]; ///< Offset into langpack offs
|
|
|
static bool _keep_gender_data = false; ///< Should we retain the gender data in the current string?
|
|
|
|
|
|
|
|
|
const char *GetStringPtr(StringID string)
|
|
|
{
|
|
|
switch (GB(string, 11, 5)) {
|
|
|
switch (GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)) {
|
|
|
/* GetGRFStringPtr doesn't handle 0xD4xx ids, we need to convert those to 0xD0xx. */
|
|
|
case 26: return GetStringPtr(GetGRFStringID(0, 0xD000 + GB(string, 0, 10)));
|
|
|
case 28: return GetGRFStringPtr(GB(string, 0, 11));
|
|
|
case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
|
|
|
case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
|
|
|
default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
|
|
|
case 26: return GetStringPtr(GetGRFStringID(0, 0xD000 + GB(string, TAB_SIZE_OFFSET, 10)));
|
|
|
case 28: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
|
|
|
case 29: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x0800);
|
|
|
case 30: return GetGRFStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS) + 0x1000);
|
|
|
default: return _langpack_offs[_langtab_start[GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)] + GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS)];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get a parsed string with most special stringcodes replaced by the string parameters.
|
|
|
* @param buffr Pointer to a string buffer where the formatted string should be written to.
|
|
|
* @param string
|
|
|
* @param args Arguments for the string.
|
|
|
* @param last Pointer just past the end of buffr.
|
|
|
* @param case_index The "case index". This will only be set when FormatString wants to print the string in a different case.
|
|
|
* @return Pointer to the final zero byte of the formatted string.
|
|
|
*/
|
|
|
char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index)
|
|
|
{
|
|
|
if (string == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, args, last);
|
|
|
|
|
|
uint index = GB(string, 0, 11);
|
|
|
uint tab = GB(string, 11, 5);
|
|
|
uint index = GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS);
|
|
|
uint tab = GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS);
|
|
|
|
|
|
switch (tab) {
|
|
|
case 4:
|
|
|
if (index >= 0xC0) {
|
|
|
return GetSpecialTownNameString(buffr, index - 0xC0, args->GetInt32(), last);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 14:
|
|
|
if (index >= 0xE4) {
|
|
|
return GetSpecialNameString(buffr, index - 0xE4, args, last);
|
|
|
}
|
|
@@ -1527,31 +1527,31 @@ bool ReadLanguagePack(const LanguageMeta
|
|
|
if (lang_pack == NULL) return false;
|
|
|
|
|
|
/* End of read data (+ terminating zero added in ReadFileToMem()) */
|
|
|
const char *end = (char *)lang_pack + len + 1;
|
|
|
|
|
|
/* We need at least one byte of lang_pack->data */
|
|
|
if (end <= lang_pack->data || !lang_pack->IsValid()) {
|
|
|
free(lang_pack);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
|
|
for (uint i = 0; i < 32; i++) {
|
|
|
for (uint i = 0; i < TAB_COUNT; i++) {
|
|
|
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
|
|
|
}
|
|
|
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
|
|
|
|
|
uint count = 0;
|
|
|
for (uint i = 0; i < 32; i++) {
|
|
|
for (uint i = 0; i < TAB_COUNT; i++) {
|
|
|
uint num = lang_pack->offsets[i];
|
|
|
_langtab_start[i] = count;
|
|
|
_langtab_num[i] = num;
|
|
|
count += num;
|
|
|
}
|
|
|
|
|
|
/* Allocate offsets */
|
|
|
char **langpack_offs = MallocT<char *>(count);
|
|
|
|
|
|
/* Fill offsets */
|
|
|
char *s = lang_pack->data;
|
|
|
len = (byte)*s++;
|
|
@@ -1840,30 +1840,30 @@ class LanguagePackGlyphSearcher : public
|
|
|
{
|
|
|
this->i = 0;
|
|
|
this->j = 0;
|
|
|
}
|
|
|
|
|
|
/* virtual */ FontSize DefaultSize()
|
|
|
{
|
|
|
return FS_NORMAL;
|
|
|
}
|
|
|
|
|
|
/* virtual */ const char *NextString()
|
|
|
{
|
|
|
if (this->i >= 32) return NULL;
|
|
|
if (this->i >= TAB_COUNT) return NULL;
|
|
|
|
|
|
const char *ret = _langpack_offs[_langtab_start[i] + j];
|
|
|
|
|
|
this->j++;
|
|
|
while (this->j >= _langtab_num[this->i] && this->i < 32) {
|
|
|
while (this->j >= _langtab_num[this->i] && this->i < TAB_COUNT) {
|
|
|
i++;
|
|
|
j = 0;
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
/* virtual */ bool Monospace()
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|