Changeset - r3641:bf8cbe28f2dc
[Not reviewed]
master
0 3 0
peter1138 - 18 years ago 2006-04-23 18:27:53
peter1138@openttd.org
(svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
3 files changed with 11 insertions and 10 deletions:
0 comments (0 inline, 0 general)
newgrf.c
Show inline comments
 
@@ -1716,24 +1716,25 @@ static void VehicleNewName(byte *buf, in
 
	 * (completely new scenarios changing all graphics and logically also
 
	 * factory names etc). We should then also support all languages (by
 
	 * name), not only the original four ones. --pasky
 
	 * TODO: Support for custom station class/type names.
 
	 * All of the above are coming.  In Time.  Some sooner than others :)*/
 

	
 
	uint8 feature;
 
	uint8 lang;
 
	uint8 num;
 
	uint16 id;
 
	uint16 endid;
 
	const char* name;
 
	bool new_scheme = _cur_grffile->grf_version < 7;
 

	
 
	check_length(len, 6, "VehicleNewName");
 
	buf++;
 
	feature  = grf_load_byte(&buf);
 
	lang     = grf_load_byte(&buf);
 
	num      = grf_load_byte(&buf);
 
	id       = (lang & 0x80) ? grf_load_word(&buf) : grf_load_byte(&buf);
 

	
 
	if (feature < GSF_AIRCRAFT+1) {
 
		id += _vehshifts[feature];
 
	}
 
	endid    = id + num;
 
@@ -1745,25 +1746,25 @@ static void VehicleNewName(byte *buf, in
 
	len -= (lang & 0x80) ? 6 : 5;
 
	for (; id < endid && len > 0; id++) {
 
		size_t ofs = strlen(name) + 1;
 

	
 
		if (ofs < 128) {
 
			DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name);
 

	
 
			switch (feature) {
 
				case GSF_TRAIN:
 
				case GSF_ROAD:
 
				case GSF_SHIP:
 
				case GSF_AIRCRAFT: {
 
					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, name);
 
					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name);
 
					if (id < TOTAL_NUM_ENGINES) SetCustomEngineName(id, string);
 
					break;
 
				}
 

	
 
#if 0
 
				case GSF_STATION:
 
					switch (GB(id, 8, 8)) {
 
						case 0xC4: { /* Station class name */
 
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)].sclass;
 
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, name));
 
							break;
 
						}
newgrf_text.c
Show inline comments
 
@@ -55,24 +55,25 @@ typedef enum grf_extended_languages {
 
	GRFLX_SLOVENIAN   = 0x2C,
 
	GRFLX_DANISH      = 0x2D,
 
	GRFLX_SWEDISH     = 0x2E,
 
	GRFLX_NORWEGIAN   = 0x2F,
 
	GRFLX_POLISH      = 0x30,
 
	GRFLX_GALICIAN    = 0x31,
 
	GRFLX_FRISIAN     = 0x32,
 
	GRFLX_ESTONIAN    = 0x34,
 
	GRFLX_FINNISH     = 0x35,
 
	GRFLX_PORTUGUESE  = 0x36,
 
	GRFLX_BRAZILIAN   = 0x37,
 
	GRFLX_TURKISH     = 0x3E,
 
	GRFLX_UNSPECIFIED = 0x7F,
 
} grf_language;
 

	
 

	
 
typedef struct iso_grf {
 
	char code[6];
 
	byte grfLangID;
 
} iso_grf;
 

	
 
/**
 
 * ISO code VS NewGrf langID conversion array.
 
 * This array is used in two ways:
 
 * 1-its ISO part is matching OpenTTD dynamic language id
 
@@ -110,46 +111,45 @@ const iso_grf iso_codes[] = {
 
	{"sv",    GRFLX_SWEDISH},
 
	{"tr",    GRFLX_TURKISH},
 
	{"gen",   GRFLB_GENERIC}   //this is not iso code, but there has to be something...
 
};
 

	
 

	
 
static uint _num_grf_texts = 0;
 
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
 
static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
 

	
 

	
 
/**
 
 * Add the new read stirng into our structure.
 
 * TODO : ajust the old scheme to the new one for german,french and spanish
 
 * Add the new read string into our structure.
 
 */
 
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, const char *text_to_add)
 
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add)
 
{
 
	GRFText *newtext;
 
	uint id;
 

	
 
	/* When working with the old language scheme (bit 6 of langid is clear) and
 
	/* When working with the old language scheme (grf_version is less than 7) and
 
	 * English or American is among the set bits, simply add it as English in
 
	 * the new scheme, i.e. as langid = 1.
 
	 * If English is set, it is pretty safe to assume the translations are not
 
	 * actually translated.
 
	 */
 
	if (!HASBIT(langid_to_add, 6)) {
 
	if (!new_scheme) {
 
		if (HASBITS(langid_to_add, GRFLB_AMERICAN | GRFLB_ENGLISH)) {
 
			langid_to_add = GRFLX_ENGLISH;
 
		} else {
 
			StringID ret = STR_EMPTY;
 
			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_GERMAN,  text_to_add);
 
			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_FRENCH,  text_to_add);
 
			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_SPANISH, text_to_add);
 
			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);
 
			return ret;
 
		}
 
	}
 

	
 
	newtext = calloc(1, sizeof(*newtext));
 
	newtext->langid = GB(langid_to_add, 0, 6);
 
	newtext->text   = strdup(text_to_add);
 
	newtext->next   = NULL;
 

	
 
	str_validate(newtext->text);
 

	
 
	for (id = 0; id < _num_grf_texts; id++) {
newgrf_text.h
Show inline comments
 
@@ -21,19 +21,19 @@ typedef struct GRFText {
 
/**
 
 * Holder of the above structure.
 
 * Putting both grfid and stringid togueter allow us to avoid duplicates,
 
 * since it is NOT SUPPOSED to happen.
 
 */
 
typedef struct GRFTextEntry {
 
	uint32 grfid;
 
	uint16 stringid;
 
	GRFText *textholder;
 
} GRFTextEntry;
 

	
 

	
 
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, const char *text_to_add);
 
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add);
 
StringID GetGRFStringID(uint32 grfid, uint16 stringid);
 
char *GetGRFString(char *buff, uint16 stringid);
 
void CleanUpStrings(void);
 
void SetCurrentGrfLangID(const char *iso_name);
 

	
 
#endif /* NEWGRF_TEXT_H */
0 comments (0 inline, 0 general)