(svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
--- a/newgrf_text.c Tue Oct 03 02:08:15 2006 +0000
+++ b/newgrf_text.c Tue Oct 03 09:25:42 2006 +0000
@@ -257,6 +257,8 @@
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 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 @@
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) {
--- a/strings.c Tue Oct 03 02:08:15 2006 +0000
+++ b/strings.c Tue Oct 03 09:25:42 2006 +0000
@@ -172,6 +172,7 @@
{
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 @@
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,