summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-03-08 16:51:08 +0000
committerfrosch <frosch@openttd.org>2009-03-08 16:51:08 +0000
commit987e72f4f2d89da1575b0c55eccdaff0d1ad4f99 (patch)
treed0b5e144e2002e62ecfeb6cffe5e5bf0090a2aea /src/saveload
parent4a5c4f6089b344c4e385a1f1e4d26545f46f4984 (diff)
downloadopenttd-987e72f4f2d89da1575b0c55eccdaff0d1ad4f99.tar.xz
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/engine_sl.cpp32
-rw-r--r--src/saveload/saveload.cpp4
2 files changed, 36 insertions, 0 deletions
diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp
index 29772c625..8da2aa879 100644
--- a/src/saveload/engine_sl.cpp
+++ b/src/saveload/engine_sl.cpp
@@ -111,7 +111,39 @@ static void Load_ENGS()
}
}
+/** Save and load the mapping between the engine id in the pool, and the grf file it came from. */
+static const SaveLoad _engine_id_mapping_desc[] = {
+ SLE_VAR(EngineIDMapping, grfid, SLE_UINT32),
+ SLE_VAR(EngineIDMapping, internal_id, SLE_UINT16),
+ SLE_VAR(EngineIDMapping, type, SLE_UINT8),
+ SLE_VAR(EngineIDMapping, substitute_id, SLE_UINT8),
+ SLE_END()
+};
+
+static void Save_EIDS()
+{
+ const EngineIDMapping *end = _engine_mngr.End();
+ uint index = 0;
+ for (EngineIDMapping *eid = _engine_mngr.Begin(); eid != end; eid++, index++) {
+ SlSetArrayIndex(index);
+ SlObject(eid, _engine_id_mapping_desc);
+ }
+}
+
+static void Load_EIDS()
+{
+ int index;
+
+ _engine_mngr.Clear();
+
+ while ((index = SlIterateArray()) != -1) {
+ EngineIDMapping *eid = _engine_mngr.Append();
+ SlObject(eid, _engine_id_mapping_desc);
+ }
+}
+
extern const ChunkHandler _engine_chunk_handlers[] = {
+ { 'EIDS', Save_EIDS, Load_EIDS, CH_ARRAY },
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY },
{ 'ENGS', NULL, Load_ENGS, CH_RIFF | CH_LAST },
};
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 390f36b3c..f30440d5a 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -34,6 +34,7 @@
#include "../fileio_func.h"
#include "../gamelog.h"
#include "../string_func.h"
+#include "../engine_base.h"
#include "table/strings.h"
@@ -1675,6 +1676,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
/* Load a TTDLX or TTDPatch game */
if (mode == SL_OLD_LOAD) {
+ _engine_mngr.ResetToDefaultMapping();
InitializeGame(256, 256, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
GamelogReset();
if (!LoadOldSaveGame(filename)) return SL_REINIT;
@@ -1789,6 +1791,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, err_str);
}
+ _engine_mngr.ResetToDefaultMapping();
+
/* Old maps were hardcoded to 256x256 and thus did not contain
* any mapsize information. Pre-initialize to 256x256 to not to
* confuse old games */