(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)

This commit is contained in:
peter1138 2006-10-03 09:25:42 +00:00
parent 753b572400
commit 7be5422d83
2 changed files with 25 additions and 3 deletions

View File

@ -257,6 +257,8 @@ 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
@ -264,6 +266,10 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
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++) {
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
return (GRFTAB << TABSIZE) + id;
@ -280,6 +286,10 @@ char *GetGRFString(char *buff, uint16 stringid)
const GRFText *search_text;
assert(_grf_text[stringid].grfid != 0);
/* Remember this grfid in case the string has included text */
_last_grfid = _grf_text[stringid].grfid;
/*Search the list of lang-strings of this stringid for current lang */
for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) {
if (search_text->langid == _currentLangID) {

View File

@ -172,6 +172,7 @@ static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
{
uint index = GB(string, 0, 11);
uint tab = GB(string, 11, 5);
char buff[512];
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString");
@ -190,14 +191,25 @@ static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
case 15:
return GetName(index, buffr);
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, argv);
}
break;
case 28:
return GetGRFString(buffr, index);
GetGRFString(buff, index);
return FormatString(buffr, buff, argv, 0);
case 29:
return GetGRFString(buffr, index + 0x800);
GetGRFString(buff, index + 0x800);
return FormatString(buffr, buff, argv, 0);
case 30:
return GetGRFString(buffr, index + 0x1000);
GetGRFString(buff, index + 0x1000);
return FormatString(buffr, buff, argv, 0);
case 31:
// dynamic strings. These are NOT to be passed through the formatter,