summaryrefslogtreecommitdiff
path: root/newgrf_text.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-10-03 14:04:43 +0000
committerpeter1138 <peter1138@openttd.org>2006-10-03 14:04:43 +0000
commit34a395e6e82f43e6e4053edf9e501e43dae8fa35 (patch)
treeb7d456b88656c7f6ec46f3454789a02f43db8ebc /newgrf_text.c
parentf2a1867e11bad5c3f268e7f2cb9bb5d5497c2271 (diff)
downloadopenttd-34a395e6e82f43e6e4053edf9e501e43dae8fa35.tar.xz
(svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
Diffstat (limited to 'newgrf_text.c')
-rw-r--r--newgrf_text.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/newgrf_text.c b/newgrf_text.c
index 621e40325..0c576f006 100644
--- a/newgrf_text.c
+++ b/newgrf_text.c
@@ -247,9 +247,21 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
_grf_text[id].def_string = def_string;
_grf_text[id].textholder = newtext;
} else {
- GRFText *textptr = _grf_text[id].textholder;
- while (textptr->next != NULL) textptr = textptr->next;
- textptr->next = newtext;
+ GRFText **ptext, *text;
+ bool replaced = false;
+
+ /* Loop through all languages and see if we can replace a string */
+ for (ptext = &_grf_text[id].textholder; (text = *ptext) != NULL; ptext = &text->next) {
+ if (text->langid != GB(langid_to_add, 0, 6)) continue;
+ newtext->next = text->next;
+ *ptext = newtext;
+ free(text);
+ replaced = true;
+ break;
+ }
+
+ /* If a string wasn't replaced, then we must append the new string */
+ if (!replaced) *ptext = newtext;
}
DEBUG(grf, 2)("Added 0x%X: grfid 0x%X string 0x%X lang 0x%X string %s", id, grfid, stringid, newtext->langid, newtext->text);