(svn r26242) -Codechange: Use GRFFile that filled the TextRefStack to translate StringIDs from the TextRefStack, instead of passing stuff via global vars.

This commit is contained in:
frosch 2014-01-12 18:00:55 +00:00
parent 7b238142b8
commit bc53bbb8b6
2 changed files with 7 additions and 23 deletions

View File

@ -56,8 +56,8 @@ StringID TTDPStringIDToOTTDStringIDMapping(StringID str)
STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
};
/* A string straight from a NewGRF; no need to remap this as it's already mapped. */
if (IsInsideMM(str, 0xD000, 0xD7FF)) return str;
/* A string straight from a NewGRF; this was already translated by MapGRFStringID(). */
assert(!IsInsideMM(str, 0xD000, 0xD7FF));
#define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
assert_compile(stringend - stringid == end - begin); \
@ -754,20 +754,12 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
return (GRFTAB << TABSIZE) + id;
}
/* Used to remember the grfid that the last retrieved string came from */
static uint32 _last_grfid = 0;
/**
* Returns the index for this stringid associated with its grfID
*/
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
{
uint id;
/* grfid is zero when we're being called via an include */
if (grfid == 0) grfid = _last_grfid;
for (id = 0; id < _num_grf_texts; id++) {
for (uint id = 0; id < _num_grf_texts; id++) {
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
return (GRFTAB << TABSIZE) + id;
}
@ -809,9 +801,6 @@ const char *GetGRFStringPtr(uint16 stringid)
{
assert(_grf_text[stringid].grfid != 0);
/* Remember this grfid in case the string has included text */
_last_grfid = _grf_text[stringid].grfid;
const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder);
if (str != NULL) return str;
@ -1108,7 +1097,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const
case SCC_NEWGRF_UNPRINT: *buff = max(*buff - Utf8Consume(str), buf_start); break;
case SCC_NEWGRF_PRINT_WORD_STRING_ID:
*argv = TTDPStringIDToOTTDStringIDMapping(_newgrf_textrefstack.PopUnsignedWord());
*argv = MapGRFStringID(_newgrf_textrefstack.grffile->grfid, _newgrf_textrefstack.PopUnsignedWord());
break;
}
}

View File

@ -192,8 +192,8 @@ const char *GetStringPtr(StringID string)
{
switch (GB(string, TAB_COUNT_OFFSET, TAB_COUNT_BITS)) {
case GAME_TEXT_TAB: return GetGameStringPtr(GB(string, TAB_SIZE_OFFSET, TAB_SIZE_BITS));
/* GetGRFStringPtr doesn't handle 0xD4xx ids, we need to convert those to 0xD0xx. */
case 26: return GetStringPtr(GetGRFStringID(0, 0xD000 + GB(string, TAB_SIZE_OFFSET, 10)));
/* 0xD0xx and 0xD4xx IDs have been converted earlier. */
case 26: NOT_REACHED();
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);
@ -242,12 +242,7 @@ char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, co
return FormatString(buffr, GetGameStringPtr(index), args, last, case_index, true);
case 26:
/* Include string within newgrf text (format code 81) */
if (HasBit(index, 10)) {
StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
return GetStringWithArgs(buffr, string, args, last, case_index);
}
break;
NOT_REACHED();
case 28:
return FormatString(buffr, GetGRFStringPtr(index), args, last, case_index);