(svn r21178) -Codechange: pass the language_id to TranslateTTDPatchCodes as well

This commit is contained in:
rubidium 2010-11-13 19:15:26 +00:00
parent 034eb834cc
commit fc75b00992
3 changed files with 15 additions and 8 deletions

View File

@ -5373,7 +5373,7 @@ static void GRFLoadError(ByteReader *buf)
if (buf->HasData()) {
const char *message = buf->ReadString();
error->custom_message = TranslateTTDPatchCodes(_cur_grffile->grfid, message);
error->custom_message = TranslateTTDPatchCodes(_cur_grffile->grfid, lang, message);
} else {
grfmsg(7, "GRFLoadError: No custom message supplied.");
error->custom_message = strdup("");
@ -5385,7 +5385,7 @@ static void GRFLoadError(ByteReader *buf)
if (buf->HasData()) {
const char *data = buf->ReadString();
error->data = TranslateTTDPatchCodes(_cur_grffile->grfid, data);
error->data = TranslateTTDPatchCodes(_cur_grffile->grfid, lang, data);
} else {
grfmsg(7, "GRFLoadError: No message data supplied.");
error->data = strdup("");
@ -5926,7 +5926,7 @@ static void FeatureTownName(ByteReader *buf)
const char *name = buf->ReadString();
char *lang_name = TranslateTTDPatchCodes(grfid, name);
char *lang_name = TranslateTTDPatchCodes(grfid, lang, name);
grfmsg(6, "FeatureTownName: lang 0x%X -> '%s'", lang, lang_name);
free(lang_name);
@ -5972,7 +5972,7 @@ static void FeatureTownName(ByteReader *buf)
townname->partlist[id][i].parts[j].data.id = ref_id;
} else {
const char *text = buf->ReadString();
townname->partlist[id][i].parts[j].data.text = TranslateTTDPatchCodes(grfid, text);
townname->partlist[id][i].parts[j].data.text = TranslateTTDPatchCodes(grfid, 0, text);
grfmsg(6, "FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[id][i].parts[j].data.text, prob);
}
townname->partlist[id][i].parts[j].prob = prob;

View File

@ -196,7 +196,14 @@ static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used.
char *TranslateTTDPatchCodes(uint32 grfid, const char *str)
/**
* Translate TTDPatch string codes into something OpenTTD can handle (better).
* @param grfid The (NewGRF) ID associated with this string
* @param language_id The (NewGRF) language ID associated with this string.
* @param str The string to translate.
* @return The translated string.
*/
char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, const char *str)
{
char *tmp = MallocT<char>(strlen(str) * 10 + 1); // Allocate space to allow for expansion
char *d = tmp;
@ -380,7 +387,7 @@ void AddGRFTextToList(GRFText **list, GRFText *text_to_add)
*/
void AddGRFTextToList(struct GRFText **list, byte langid, uint32 grfid, const char *text_to_add)
{
char *translatedtext = TranslateTTDPatchCodes(grfid, text_to_add);
char *translatedtext = TranslateTTDPatchCodes(grfid, langid, text_to_add);
GRFText *newtext = GRFText::New(langid, translatedtext);
free(translatedtext);
@ -449,7 +456,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
/* Too many strings allocated, return empty */
if (id == lengthof(_grf_text)) return STR_EMPTY;
translatedtext = TranslateTTDPatchCodes(grfid, text_to_add);
translatedtext = TranslateTTDPatchCodes(grfid, langid_to_add, text_to_add);
GRFText *newtext = GRFText::New(langid_to_add, translatedtext);

View File

@ -20,7 +20,7 @@ const char *GetGRFStringFromGRFText(const struct GRFText *text);
const char *GetGRFStringPtr(uint16 stringid);
void CleanUpStrings();
void SetCurrentGrfLangID(byte language_id);
char *TranslateTTDPatchCodes(uint32 grfid, const char *str);
char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, const char *str);
struct GRFText *DuplicateGRFText(struct GRFText *orig);
void AddGRFTextToList(struct GRFText **list, struct GRFText *text_to_add);
void AddGRFTextToList(struct GRFText **list, byte langid, uint32 grfid, const char *text_to_add);