changeset 4711:155ac8c272d3 draft

(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.
author peter1138 <peter1138@openttd.org>
date Tue, 03 Oct 2006 14:04:43 +0000
parents 6c2275c7b6b3
children 527ccf4629fb
files newgrf.c newgrf_text.c
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/newgrf.c
+++ b/newgrf.c
@@ -1960,7 +1960,7 @@
 	for (; id < endid && len > 0; id++) {
 		size_t ofs = strlen(name) + 1;
 
-		if (ofs > 1 && ofs < 128) {
+		if (ofs < 128) {
 			DEBUG(grf, 8) ("FeatureNewName: %d <- %s", id, name);
 
 			switch (feature) {
--- a/newgrf_text.c
+++ b/newgrf_text.c
@@ -247,9 +247,21 @@
 		_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);