diff options
author | yexo <yexo@openttd.org> | 2010-12-08 13:44:01 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-12-08 13:44:01 +0000 |
commit | ac0e83a7e22c3ed94130b2fc4de62fe38478b121 (patch) | |
tree | 2829f35d5085adfb5b9a3b01bbf4bba98c16cc52 /src/strings.cpp | |
parent | 5c181fe5564926c0f23cfe483a1245fa2ee3c7c4 (diff) | |
download | openttd-ac0e83a7e22c3ed94130b2fc4de62fe38478b121.tar.xz |
(svn r21435) -Fix: NewGRF strings that referenced a value that was set by a string command later in the string failed
Diffstat (limited to 'src/strings.cpp')
-rw-r--r-- | src/strings.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/strings.cpp b/src/strings.cpp index f6c62a947..f3db95fb1 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -56,7 +56,7 @@ static char *StationGetSpecialString(char *buff, int x, const char *last); static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last); static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char *last); -static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last); +static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last, bool dry_run = false); struct LanguagePack : public LanguagePackHeader { char data[]; // list of strings @@ -583,8 +583,19 @@ uint ConvertDisplaySpeedToSpeed(uint speed) return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m; } -static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last) +static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last, bool dry_run) { + if (UsingNewGRFTextStack() && !dry_run) { + /* Values from the NewGRF text stack are only copied to the normal + * argv array at the time they are encountered. That means that if + * another string command references a value later in the string it + * would fail. We solve that by running FormatString twice. The first + * pass makes sure the argv array is correctly filled and the second + * pass can reference later values without problems. */ + struct TextRefStack *backup = CreateTextRefStackBackup(); + FormatString(buff, str, argv, casei, last, true); + RestoreTextRefStackBackup(backup); + } WChar b; int64 *argv_orig = argv; uint modifier = 0; |