NewGRF: Use per-GRF text ID map in GetGRFStringID
This commit is contained in:
@@ -12461,9 +12461,6 @@ void LoadNewGRF(uint load_index, uint num_baseset)
|
||||
|
||||
/* Pseudo sprite processing is finished; free temporary stuff */
|
||||
_cur.ClearDataForNextFile();
|
||||
for (GRFFile * const file : _grf_files) {
|
||||
file->string_map.clear();
|
||||
}
|
||||
_callback_result_cache.clear();
|
||||
|
||||
/* Call any functions that should be run after GRFs have been loaded. */
|
||||
|
@@ -614,11 +614,18 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
|
||||
*/
|
||||
StringID GetGRFStringID(uint32 grfid, StringID stringid)
|
||||
{
|
||||
extern GRFFile *GetFileByGRFIDExpectCurrent(uint32 grfid);
|
||||
GRFFile *grf = GetFileByGRFIDExpectCurrent(grfid);
|
||||
if (unlikely(grf == nullptr)) {
|
||||
for (uint id = 0; id < _num_grf_texts; id++) {
|
||||
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
||||
return MakeStringID(TEXT_TAB_NEWGRF_START, id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto iter = grf->string_map.find(stringid);
|
||||
if (iter != grf->string_map.end()) return MakeStringID(TEXT_TAB_NEWGRF_START, iter->second);
|
||||
}
|
||||
|
||||
return STR_UNDEFINED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user