From d6004d17d4f7616cff4f905ada03fa7d1626aa0e Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 11 Aug 2010 18:57:48 +0000 Subject: (svn r20449) -Codechange: unduplicate saving/loading of NewGRF ID + local id -> OpenTTD spec mappings --- src/saveload/newgrf_sl.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/saveload/newgrf_sl.cpp') diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index c66d7739b..b4405b171 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -17,6 +17,39 @@ #include "../fios.h" #include "saveload.h" +#include "newgrf_sl.h" + +/** Save and load the mapping between a spec and the NewGRF it came from. */ +static const SaveLoad _newgrf_mapping_desc[] = { + SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), + SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8), + SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8), + SLE_END() +}; + +void Save_NewGRFMapping(const OverrideManagerBase &mapping) +{ + for (uint i = 0; i < mapping.GetMaxMapping(); i++) { + SlSetArrayIndex(i); + SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc); + } +} + +void Load_NewGRFMapping(OverrideManagerBase &mapping) +{ + /* Clear the current mapping stored. + * This will create the manager if ever it is not yet done */ + mapping.ResetMapping(); + + uint max_id = mapping.GetMaxMapping(); + + int index; + while ((index = SlIterateArray()) != -1) { + if ((uint)index >= max_id) break; + SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc); + } +} + static const SaveLoad _grfconfig_desc[] = { SLE_STR(GRFConfig, filename, SLE_STR, 0x40), -- cgit v1.2.3-54-g00ecf