(svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.

pull/155/head
peter1138 17 years ago
parent 9e7ad199b5
commit 3e017833b2

@ -405,7 +405,7 @@ StringID GetGRFStringID(uint32 grfid, uint16 stringid)
}
char *GetGRFString(char *buff, uint16 stringid, const char* last)
const char *GetGRFStringPtr(uint16 stringid)
{
const GRFText *default_text = NULL;
const GRFText *search_text;
@ -418,7 +418,7 @@ char *GetGRFString(char *buff, uint16 stringid, const char* last)
/*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) {
return strecpy(buff, search_text->text, last);
return search_text->text;
}
/* If the current string is English or American, set it as the
@ -429,10 +429,10 @@ char *GetGRFString(char *buff, uint16 stringid, const char* last)
}
/* If there is a fallback string, return that */
if (default_text != NULL) return strecpy(buff, default_text->text, last);
if (default_text != NULL) return default_text->text;
/* Use the default string ID if the fallback string isn't available */
return GetString(buff, _grf_text[stringid].def_string, last);
return GetStringPtr(_grf_text[stringid].def_string);
}
/**

@ -8,7 +8,7 @@
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, const char* last);
const char *GetGRFStringPtr(uint16 stringid);
void CleanUpStrings();
void SetCurrentGrfLangID(const char *iso_name);
char *TranslateTTDPatchCodes(const char *str);

@ -104,9 +104,14 @@ static const char *_bound_strings[NUM_BOUND_STRINGS];
* the indices will be reused. */
static int _bind_index;
static const char *GetStringPtr(StringID string)
const char *GetStringPtr(StringID string)
{
return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
switch (GB(string, 11, 5)) {
case 28: return GetGRFStringPtr(GB(string, 0, 11));
case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
}
}
/** The highest 8 bits of string contain the "case index".
@ -125,7 +130,6 @@ static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, cons
uint index = GB(string, 0, 11);
uint tab = GB(string, 11, 5);
char buff[512];
switch (tab) {
case 4:
@ -139,7 +143,8 @@ static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, cons
break;
case 15:
error("Boo!");
/* Old table for custom names. This is no longer used */
error("Incorrect conversion of custom name string.");
case 26:
/* Include string within newgrf text (format code 81) */
@ -150,16 +155,13 @@ static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, cons
break;
case 28:
GetGRFString(buff, index, lastof(buff));
return FormatString(buffr, buff, argv, 0, last);
return FormatString(buffr, GetGRFStringPtr(index), argv, 0, last);
case 29:
GetGRFString(buff, index + 0x800, lastof(buff));
return FormatString(buffr, buff, argv, 0, last);
return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, 0, last);
case 30:
GetGRFString(buff, index + 0x1000, lastof(buff));
return FormatString(buffr, buff, argv, 0, last);
return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, 0, last);
case 31:
/* dynamic strings. These are NOT to be passed through the formatter,
@ -695,8 +697,7 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
}
case SCC_GENDER_LIST: { // {G 0 Der Die Das}
char buffr[512];
const char *s = GetStringWithArgs(buffr, argv_orig[(byte)*str++], argv, last); // contains the string that determines gender.
const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
int len;
int gender = 0;
if (s != NULL) {

@ -9,6 +9,7 @@
char *InlineString(char *buf, StringID string);
char *GetString(char *buffr, StringID string, const char *last);
const char *GetStringPtr(StringID string);
extern char _userstring[128];

Loading…
Cancel
Save