(svn r27756) -Codechange: Add StringTab enum
This commit is contained in:
@@ -187,20 +187,20 @@ struct LanguagePack : public LanguagePackHeader {
|
||||
|
||||
static char **_langpack_offs;
|
||||
static LanguagePack *_langpack;
|
||||
static uint _langtab_num[TAB_COUNT]; ///< Offset into langpack offs
|
||||
static uint _langtab_start[TAB_COUNT]; ///< Offset into langpack offs
|
||||
static uint _langtab_num[TEXT_TAB_END]; ///< Offset into langpack offs
|
||||
static uint _langtab_start[TEXT_TAB_END]; ///< Offset into langpack offs
|
||||
static bool _scan_for_gender_data = false; ///< Are we scanning for the gender of the current string? (instead of formatting it)
|
||||
|
||||
|
||||
const char *GetStringPtr(StringID string)
|
||||
{
|
||||
switch (GetStringTab(string)) {
|
||||
case GAME_TEXT_TAB: return GetGameStringPtr(GetStringIndex(string));
|
||||
case TEXT_TAB_GAMESCRIPT: return GetGameStringPtr(GetStringIndex(string));
|
||||
/* 0xD0xx and 0xD4xx IDs have been converted earlier. */
|
||||
case 26: NOT_REACHED();
|
||||
case 28: return GetGRFStringPtr(GetStringIndex(string));
|
||||
case 29: return GetGRFStringPtr(GetStringIndex(string) + 0x0800);
|
||||
case 30: return GetGRFStringPtr(GetStringIndex(string) + 0x1000);
|
||||
case TEXT_TAB_OLD_NEWGRF: NOT_REACHED();
|
||||
case TEXT_TAB_NEWGRF1: return GetGRFStringPtr(GetStringIndex(string));
|
||||
case TEXT_TAB_NEWGRF2: return GetGRFStringPtr(GetStringIndex(string) + 0x0800);
|
||||
case TEXT_TAB_NEWGRF3: return GetGRFStringPtr(GetStringIndex(string) + 0x1000);
|
||||
default: return _langpack_offs[_langtab_start[GetStringTab(string)] + GetStringIndex(string)];
|
||||
}
|
||||
}
|
||||
@@ -220,42 +220,45 @@ char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, co
|
||||
if (string == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, args, last);
|
||||
|
||||
uint index = GetStringIndex(string);
|
||||
uint tab = GetStringTab(string);
|
||||
StringTab tab = GetStringTab(string);
|
||||
|
||||
switch (tab) {
|
||||
case 4:
|
||||
case TEXT_TAB_TOWN:
|
||||
if (index >= 0xC0 && !game_script) {
|
||||
return GetSpecialTownNameString(buffr, index - 0xC0, args->GetInt32(), last);
|
||||
}
|
||||
break;
|
||||
|
||||
case 14:
|
||||
case TEXT_TAB_SPECIAL:
|
||||
if (index >= 0xE4 && !game_script) {
|
||||
return GetSpecialNameString(buffr, index - 0xE4, args, last);
|
||||
}
|
||||
break;
|
||||
|
||||
case 15:
|
||||
case TEXT_TAB_OLD_CUSTOM:
|
||||
/* Old table for custom names. This is no longer used */
|
||||
if (!game_script) {
|
||||
error("Incorrect conversion of custom name string.");
|
||||
}
|
||||
break;
|
||||
|
||||
case GAME_TEXT_TAB:
|
||||
case TEXT_TAB_GAMESCRIPT:
|
||||
return FormatString(buffr, GetGameStringPtr(index), args, last, case_index, true);
|
||||
|
||||
case 26:
|
||||
case TEXT_TAB_OLD_NEWGRF:
|
||||
NOT_REACHED();
|
||||
|
||||
case 28:
|
||||
case TEXT_TAB_NEWGRF1:
|
||||
return FormatString(buffr, GetGRFStringPtr(index), args, last, case_index);
|
||||
|
||||
case 29:
|
||||
case TEXT_TAB_NEWGRF2:
|
||||
return FormatString(buffr, GetGRFStringPtr(index + 0x0800), args, last, case_index);
|
||||
|
||||
case 30:
|
||||
case TEXT_TAB_NEWGRF3:
|
||||
return FormatString(buffr, GetGRFStringPtr(index + 0x1000), args, last, case_index);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (index >= _langtab_num[tab]) {
|
||||
@@ -886,7 +889,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
buff = strecat(buff, "(invalid sub-StringID)", last);
|
||||
break;
|
||||
}
|
||||
param = MakeStringID(GAME_TEXT_TAB, param);
|
||||
param = MakeStringID(TEXT_TAB_GAMESCRIPT, param);
|
||||
}
|
||||
|
||||
sub_args.SetParam(i++, param);
|
||||
@@ -901,7 +904,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
/* If we didn't error out, we can actually print the string. */
|
||||
if (*str != '\0') {
|
||||
str = p;
|
||||
buff = GetStringWithArgs(buff, MakeStringID(GAME_TEXT_TAB, stringid), &sub_args, last, true);
|
||||
buff = GetStringWithArgs(buff, MakeStringID(TEXT_TAB_GAMESCRIPT, stringid), &sub_args, last, true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
@@ -1017,7 +1020,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
|
||||
case SCC_STRING: {// {STRING}
|
||||
StringID str = args->GetInt32(SCC_STRING);
|
||||
if (game_script && GetStringTab(str) != GAME_TEXT_TAB) break;
|
||||
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT) break;
|
||||
/* 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 */
|
||||
@@ -1036,7 +1039,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
case SCC_STRING7: { // {STRING1..7}
|
||||
/* Strings that consume arguments */
|
||||
StringID str = args->GetInt32(b);
|
||||
if (game_script && GetStringTab(str) != GAME_TEXT_TAB) break;
|
||||
if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT) break;
|
||||
uint size = b - SCC_STRING1 + 1;
|
||||
if (game_script && size > args->GetDataLeft()) {
|
||||
buff = strecat(buff, "(too many parameters)", last);
|
||||
@@ -1736,13 +1739,13 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
|
||||
}
|
||||
|
||||
#if TTD_ENDIAN == TTD_BIG_ENDIAN
|
||||
for (uint i = 0; i < TAB_COUNT; i++) {
|
||||
for (uint i = 0; i < TEXT_TAB_END; i++) {
|
||||
lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
|
||||
}
|
||||
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
|
||||
|
||||
uint count = 0;
|
||||
for (uint i = 0; i < TAB_COUNT; i++) {
|
||||
for (uint i = 0; i < TEXT_TAB_END; i++) {
|
||||
uint16 num = lang_pack->offsets[i];
|
||||
if (num > TAB_SIZE) {
|
||||
free(lang_pack);
|
||||
@@ -2051,12 +2054,12 @@ class LanguagePackGlyphSearcher : public MissingGlyphSearcher {
|
||||
|
||||
/* virtual */ const char *NextString()
|
||||
{
|
||||
if (this->i >= TAB_COUNT) return NULL;
|
||||
if (this->i >= TEXT_TAB_END) return NULL;
|
||||
|
||||
const char *ret = _langpack_offs[_langtab_start[this->i] + this->j];
|
||||
|
||||
this->j++;
|
||||
while (this->i < TAB_COUNT && this->j >= _langtab_num[this->i]) {
|
||||
while (this->i < TEXT_TAB_END && this->j >= _langtab_num[this->i]) {
|
||||
this->i++;
|
||||
this->j = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user