/** * Finds the name of a NewGRF in the list of names for unknown GRFs. An * unknown GRF is a GRF where the .grf is not found during scanning. * * The names are resolved via UDP calls to servers that should know the name, * though the replies may not come. This leaves "<Unknown>" as name, though * that shouldn't matter _very_ much as they need GRF crawler or so to look * up the GRF anyway and that works better with the GRF ID. * * @param grfid the GRF ID part of the 'unique' GRF identifier * @param md5sum the MD5 checksum part of the 'unique' GRF identifier * @param create whether to create a new GRFConfig if the GRFConfig did not * exist in the fake list of GRFConfigs. * @return The GRFTextWrapper of the name of the GRFConfig with the given GRF ID * and MD5 checksum or NULL when it does not exist and create is false. * This value must NEVER be freed by the caller. */ GRFTextWrapper *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create) { UnknownGRF *grf; static UnknownGRF *unknown_grfs = NULL; for (grf = unknown_grfs; grf != NULL; grf = grf->next) { if (grf->grfid == grfid) { if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name; } } if (!create) return NULL; grf = CallocT<UnknownGRF>(1); grf->grfid = grfid; grf->next = unknown_grfs; grf->name = new GRFTextWrapper(); grf->name->AddRef(); AddGRFTextToList(&grf->name->text, UNKNOWN_GRF_NAME_PLACEHOLDER); memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum)); unknown_grfs = grf; return grf->name; }
/** * Add a string to a GRFText list. * @param list The list where the text should be added to. * @param langid The language of the new text. * @param grfid The grfid where this string is defined. * @param allow_newlines Whether newlines are allowed in this string. * @param text_to_add The text to add to the list. * @note All text-codes will be translated. */ void AddGRFTextToList(struct GRFText **list, byte langid, uint32 grfid, bool allow_newlines, const char *text_to_add) { int len; char *translatedtext = TranslateTTDPatchCodes(grfid, langid, allow_newlines, text_to_add, &len); GRFText *newtext = GRFText::New(langid, translatedtext, len); free(translatedtext); AddGRFTextToList(list, newtext); }
/** * Add the new read string into our structure. */ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string) { char *translatedtext; uint id; /* 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 (!new_scheme) { if (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, GRFLX_GERMAN, true, allow_newlines, text_to_add, def_string); if (langid_to_add & GRFLB_FRENCH) ret = AddGRFString(grfid, stringid, GRFLX_FRENCH, true, allow_newlines, text_to_add, def_string); if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, GRFLX_SPANISH, true, allow_newlines, text_to_add, def_string); return ret; } } for (id = 0; id < _num_grf_texts; id++) { if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) { break; } } /* Too many strings allocated, return empty */ if (id == lengthof(_grf_text)) return STR_EMPTY; int len; translatedtext = TranslateTTDPatchCodes(grfid, langid_to_add, allow_newlines, text_to_add, &len); GRFText *newtext = GRFText::New(langid_to_add, translatedtext, len); free(translatedtext); /* If we didn't find our stringid and grfid in the list, allocate a new id */ if (id == _num_grf_texts) _num_grf_texts++; if (_grf_text[id].textholder == NULL) { _grf_text[id].grfid = grfid; _grf_text[id].stringid = stringid; _grf_text[id].def_string = def_string; } AddGRFTextToList(&_grf_text[id].textholder, newtext); grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text); return (GRFTAB << TABSIZE) + id; }
/** * Add a GRFText to a GRFText list. The text should not contain any text-codes. * The text will be added as a 'default language'-text. * @param list The list where the text should be added to. * @param text_to_add The text to add to the list. */ void AddGRFTextToList(struct GRFText **list, const char *text_to_add) { AddGRFTextToList(list, GRFText::New(0x7F, text_to_add, strlen(text_to_add) + 1)); }