summaryrefslogtreecommitdiff
path: root/src/saveload/newgrf_sl.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-11 18:57:48 +0000
committerrubidium <rubidium@openttd.org>2010-08-11 18:57:48 +0000
commitd6004d17d4f7616cff4f905ada03fa7d1626aa0e (patch)
treea2c1e4382dc2455ca2f605829572657b156d40be /src/saveload/newgrf_sl.cpp
parente0a3a0fd54cff08f8d721dded1dc9651296de1d2 (diff)
downloadopenttd-d6004d17d4f7616cff4f905ada03fa7d1626aa0e.tar.xz
(svn r20449) -Codechange: unduplicate saving/loading of NewGRF ID + local id -> OpenTTD spec mappings
Diffstat (limited to 'src/saveload/newgrf_sl.cpp')
-rw-r--r--src/saveload/newgrf_sl.cpp33
1 files changed, 33 insertions, 0 deletions
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),