|
|
|
@ -573,23 +573,30 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint id;
|
|
|
|
|
for (id = 0; id < _num_grf_texts; id++) {
|
|
|
|
|
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
|
|
|
|
break;
|
|
|
|
|
extern GRFFile *GetFileByGRFIDExpectCurrent(uint32 grfid);
|
|
|
|
|
GRFFile *grf = GetFileByGRFIDExpectCurrent(grfid);
|
|
|
|
|
if (grf == nullptr) return STR_EMPTY;
|
|
|
|
|
|
|
|
|
|
auto iter = grf->string_map.lower_bound(stringid);
|
|
|
|
|
if (iter != grf->string_map.end() && iter->first == stringid) {
|
|
|
|
|
/* Found */
|
|
|
|
|
id = iter->second;
|
|
|
|
|
} else {
|
|
|
|
|
/* Allocate new ID */
|
|
|
|
|
id = _num_grf_texts;
|
|
|
|
|
|
|
|
|
|
/* Too many strings allocated, return empty */
|
|
|
|
|
if (id == lengthof(_grf_text)) {
|
|
|
|
|
_grf_bug_too_many_strings = true;
|
|
|
|
|
return STR_EMPTY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Too many strings allocated, return empty */
|
|
|
|
|
if (id == lengthof(_grf_text)) {
|
|
|
|
|
_grf_bug_too_many_strings = true;
|
|
|
|
|
return STR_EMPTY;
|
|
|
|
|
grf->string_map.insert(iter, std::make_pair(stringid, id));
|
|
|
|
|
_num_grf_texts++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string newtext = TranslateTTDPatchCodes(grfid, langid_to_add, allow_newlines, text_to_add);
|
|
|
|
|
|
|
|
|
|
/* 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.empty()) {
|
|
|
|
|
_grf_text[id].grfid = grfid;
|
|
|
|
|
_grf_text[id].stringid = stringid;
|
|
|
|
|