From 83dfbba98a2565fa6a89d1d551fef24e701fa251 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 1 Jan 2025 22:11:44 +0000 Subject: [PATCH] Change: [NewGRF] Use deferred string mapping for bridge and currency names. This means that the strings can now be defined after the properties using them, as is the case with all other features. --- src/newgrf.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index d1fe78f36b..06fd88a4ae 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2327,18 +2327,17 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR bridge->avail_year = Clamp(TimerGameCalendar::Year(buf.ReadDWord()), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR); break; - case 0x10: { // purchase string - StringID newone = GetGRFStringID(_cur.grffile->grfid, buf.ReadWord()); - if (newone != STR_UNDEFINED) bridge->material = newone; + case 0x10: // purchase string + AddStringForMapping(buf.ReadWord(), &bridge->material); break; - } - case 0x11: // description of bridge with rails or roads - case 0x12: { - StringID newone = GetGRFStringID(_cur.grffile->grfid, buf.ReadWord()); - if (newone != STR_UNDEFINED) bridge->transport_name[prop - 0x11] = newone; + case 0x11: // description of bridge with rails + AddStringForMapping(buf.ReadWord(), &bridge->transport_name[0]); + break; + + case 0x12: // description of bridge with roads + AddStringForMapping(buf.ReadWord(), &bridge->transport_name[1]); break; - } case 0x13: // 16 bits cost multiplier bridge->price = buf.ReadWord(); @@ -2790,11 +2789,13 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By case 0x0A: { // Currency display names uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); - StringID newone = GetGRFStringID(_cur.grffile->grfid, buf.ReadWord()); - - if ((newone != STR_UNDEFINED) && (curidx < CURRENCY_END)) { - _currency_specs[curidx].name = newone; - _currency_specs[curidx].code.clear(); + if (curidx < CURRENCY_END) { + AddStringForMapping(buf.ReadWord(), [curidx](StringID str) { + _currency_specs[curidx].name = str; + _currency_specs[curidx].code.clear(); + }); + } else { + buf.ReadWord(); } break; }