Define a new string

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
User avatar
peste1
Engineer
Engineer
Posts: 47
Joined: 07 Aug 2003 10:13
Location: Monza (Milan), Italy
Contact:

Define a new string

Post by peste1 »

with ShowErrorMessage() I want to display a new error message.
But.. how can I create english.lng??

The program says:

2034: WARNING: String name 'STR_5808_ERROR' is invalid (or already used)
2035: WARNING: String STR_5808_ERROR has no definition. Using NULL value

Thanks!
Very good project!
Stefano
TTDX Configurator Translator
Alex Nipal
Engineer
Engineer
Posts: 26
Joined: 08 Mar 2004 17:55
Location: Chomutov (Komotau), Czech Republic
Contact:

Post by Alex Nipal »

How to define new string.

First, add the string into strings.h and make sure that number value (enums are number values) is not used anywhere else

Second, look into strings.c, where is this table:

Code: Select all

static const uint16 _lang_pack_num[32] = {
	0x33B, 0x11, 0x25, 0x19, 0x5D, 0x11, 0x6D, 0x08,
	0x11, 0x3C, 0x2A, 0x08, 0x19, 0x39, 0x80, 0x0,
	0x108, 0x6C, 0x38, 0x43, 0x44, 0, 0x6, 0x0,
	0,0,0,0,0,0,0,0
};
You'll have to modify the number which corresponds to the postion of enum you have modified in strings.h. Every number in this array corresponds to number of entries for each enum in strings.h. And don't forget, it is a hex. number!

Third, use the defined string where you want it, then compile program.

Forth, add new strings into english.txt (to the right position, you mustn't have it mixed) and compile with strgen.
May the blessed Czech hands will be with you...

(A nejlepsi je stejne cesky pivo a cesky holky)
User avatar
peste1
Engineer
Engineer
Posts: 47
Joined: 07 Aug 2003 10:13
Location: Monza (Milan), Italy
Contact:

Post by peste1 »

Thank you for the reply!
But... I can't find _lang_pack_num[32] in strings.c :oops:

Are u sure :) ?
Stefano
TTDX Configurator Translator
Alex Nipal
Engineer
Engineer
Posts: 26
Joined: 08 Mar 2004 17:55
Location: Chomutov (Komotau), Czech Republic
Contact:

Post by Alex Nipal »

peste1 wrote:But... I can't find _lang_pack_num[32] in strings.c
At the end of file there is:

Code: Select all

bool read_language_pack(const char *filename)
And upon this function there is the lang_pack_num array :wink:
May the blessed Czech hands will be with you...

(A nejlepsi je stejne cesky pivo a cesky holky)
User avatar
peste1
Engineer
Engineer
Posts: 47
Joined: 07 Aug 2003 10:13
Location: Monza (Milan), Italy
Contact:

Post by peste1 »

I'm sorry... but I'm new using C++ ;)

Code: Select all

bool read_language_pack(const char *filename) {
	FILE *in;
	int tot_count, i;
	byte *lang_pack;
	size_t len;
	byte **langpack_offs;
	byte *s;
	uint offs;

	in = fopen(filename, "rb");
	if (in == NULL)
		return false;

	fseek(in, 0, SEEK_END);
	len = ftell(in);
	fseek(in, 0, SEEK_SET);
	lang_pack = (byte*)malloc(len + 1); // want a traling NUL
	if (lang_pack == NULL) {
		fclose(in);
		return false;
	}
	lang_pack[len] = 0;
	fread(lang_pack, len, 1, in);
	fclose(in);

#if defined(TTD_BIG_ENDIAN)
	for(i=0; i!=32; i++) {
		((uint16*)lang_pack)[i] = READ_LE_UINT16((uint16*)lang_pack + i);
	}
#endif


	tot_count = 0;
	for(i=0; i!=32; i++) {
		uint num = ((uint16*)lang_pack)[i];
		_langtab_start[i] = tot_count;
		_langtab_num[i] = num;
		tot_count += num;
	}

	// Allocate offsets
	_langpack_offs = langpack_offs = (byte**)malloc(tot_count * sizeof(byte*));

	// Fill offsets
	s = lang_pack + 32 * sizeof(uint16);
	for(i=0; i!=tot_count; i++) {
		langpack_offs[i] = s + sizeof(uint16);
		offs = READ_LE_UINT16(s);
		s[0] = 0;// This has the effect of zero terminating the string
		s += sizeof(uint16) + offs;
	}
	return true;
}
Stefano
TTDX Configurator Translator
Alex Nipal
Engineer
Engineer
Posts: 26
Joined: 08 Mar 2004 17:55
Location: Chomutov (Komotau), Czech Republic
Contact:

Post by Alex Nipal »

it's not C++, it's only old poor C :)
a few lines higher you have the array :wink:
May the blessed Czech hands will be with you...

(A nejlepsi je stejne cesky pivo a cesky holky)
User avatar
ludde
OpenTTD Developer
OpenTTD Developer
Posts: 35
Joined: 07 Mar 2004 09:28

Post by ludde »

The array is no longer there in latest SVN. You don't need to modify there. It was just there for debugging purposes.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 33 guests