(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
authorpeter1138
Thu, 11 May 2006 16:27:46 +0000
changeset 3821 57db5bab0f24
parent 3820 952119a1503d
child 3822 49da7f0944a9
(svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
newgrf.c
newgrf_text.c
newgrf_text.h
--- a/newgrf.c	Thu May 11 15:14:50 2006 +0000
+++ b/newgrf.c	Thu May 11 16:27:46 2006 +0000
@@ -16,6 +16,7 @@
 #include "newgrf.h"
 #include "variables.h"
 #include "string.h"
+#include "table/strings.h"
 #include "bridge.h"
 #include "economy.h"
 #include "newgrf_engine.h"
@@ -1788,8 +1789,12 @@
 				case GSF_ROAD:
 				case GSF_SHIP:
 				case GSF_AIRCRAFT: {
-					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name);
-					if (id < TOTAL_NUM_ENGINES) SetCustomEngineName(id, string);
+					if (id < TOTAL_NUM_ENGINES) {
+						StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
+						SetCustomEngineName(id, string);
+					} else {
+						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
+					}
 					break;
 				}
 
@@ -1800,7 +1805,7 @@
 								grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
 							} else {
 								StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
-								SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name));
+								SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
 							}
 							break;
 
@@ -1808,7 +1813,7 @@
 							if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
 								grfmsg(GMS_WARN, "VehicleNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
 							} else {
-								_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name);
+								_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
 							}
 							break;
 
--- a/newgrf_text.c	Thu May 11 15:14:50 2006 +0000
+++ b/newgrf_text.c	Thu May 11 16:27:46 2006 +0000
@@ -13,6 +13,7 @@
 #include "debug.h"
 #include "openttd.h"
 #include "string.h"
+#include "strings.h"
 #include "variables.h"
 #include "macros.h"
 #include "table/strings.h"
@@ -165,7 +166,7 @@
 /**
  * Add the new read string into our structure.
  */
-StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add)
+StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add, StringID def_string)
 {
 	GRFText *newtext;
 	uint id;
@@ -181,9 +182,9 @@
 			langid_to_add = GRFLX_ENGLISH;
 		} else {
 			StringID ret = STR_EMPTY;
-			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_GERMAN,  true, text_to_add);
-			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_FRENCH,  true, text_to_add);
-			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_SPANISH, true, text_to_add);
+			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_GERMAN,  true, text_to_add, def_string);
+			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_FRENCH,  true, text_to_add, def_string);
+			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_SPANISH, true, text_to_add, def_string);
 			return ret;
 		}
 	}
@@ -210,6 +211,7 @@
 	if (_grf_text[id].textholder == NULL) {
 		_grf_text[id].grfid      = grfid;
 		_grf_text[id].stringid   = stringid;
+		_grf_text[id].def_string = def_string;
 		_grf_text[id].textholder = newtext;
 	} else {
 		GRFText *textptr = _grf_text[id].textholder;
@@ -242,17 +244,27 @@
 char *GetGRFString(char *buff, uint16 stringid)
 {
 	GRFText *search_text;
+	GRFText *default_text = NULL;
 
 	assert(_grf_text[stringid].grfid != 0);
 	/*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){
+		if (search_text->langid == _currentLangID) {
 			return strecpy(buff, search_text->text, NULL);
 		}
+
+		/* If the current string is English or American, set it as the
+		 * fallback language if the specific language isn't available. */
+		if (search_text->langid == GRFLX_ENGLISH || search_text->langid == GRFLX_AMERICAN) {
+			default_text = search_text;
+		}
 	}
 
-	/* Use the first text if the specific language isn't available */
-	return strecpy(buff, _grf_text[stringid].textholder->text, NULL);
+	/* If there is a fallback string, return that */
+	if (default_text != NULL) return strecpy(buff, default_text->text, NULL);
+
+	/* Use the default string ID if the fallback string isn't available */
+	return GetString(buff, _grf_text[stringid].def_string);
 }
 
 /**
--- a/newgrf_text.h	Thu May 11 15:14:50 2006 +0000
+++ b/newgrf_text.h	Thu May 11 16:27:46 2006 +0000
@@ -26,11 +26,12 @@
 typedef struct GRFTextEntry {
 	uint32 grfid;
 	uint16 stringid;
+	StringID def_string;
 	GRFText *textholder;
 } GRFTextEntry;
 
 
-StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add);
+StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add, StringID def_string);
 StringID GetGRFStringID(uint32 grfid, uint16 stringid);
 char *GetGRFString(char *buff, uint16 stringid);
 void CleanUpStrings(void);