summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-05-12 19:21:00 +0000
committerrubidium <rubidium@openttd.org>2010-05-12 19:21:00 +0000
commit93ff7d78e17ca68684065924942e40a355b58670 (patch)
tree2b363403e4e6b54d778ab55d78c2f15c27df8141 /src/saveload
parent863ff6522b671ce69a1265fe246149b25e83a847 (diff)
downloadopenttd-93ff7d78e17ca68684065924942e40a355b58670.tar.xz
(svn r19799) -Change: give depots an unique name in the same manner buoys and waypoints are named
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp8
-rw-r--r--src/saveload/depot_sl.cpp29
-rw-r--r--src/saveload/oldloader_sl.cpp2
-rw-r--r--src/saveload/saveload.cpp2
4 files changed, 34 insertions, 7 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 4ff915742..9ab519242 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -2106,6 +2106,14 @@ bool AfterLoadGame()
/* Reset tropic zone for VOID tiles, they shall not have any. */
if (IsTileType(t, MP_VOID)) SetTropicZone(t, TROPICZONE_NORMAL);
}
+
+ /* We need to properly number/name the depots.
+ * The first step is making sure none of the depots uses the
+ * 'default' names, after that we can assign the names. */
+ Depot *d;
+ FOR_ALL_DEPOTS(d) d->town_cn = UINT16_MAX;
+
+ FOR_ALL_DEPOTS(d) MakeDefaultName(d);
}
/* Road stops is 'only' updating some caches */
diff --git a/src/saveload/depot_sl.cpp b/src/saveload/depot_sl.cpp
index 3ef999780..a0b32eaac 100644
--- a/src/saveload/depot_sl.cpp
+++ b/src/saveload/depot_sl.cpp
@@ -11,14 +11,20 @@
#include "../stdafx.h"
#include "../depot_base.h"
+#include "../town.h"
#include "saveload.h"
+static TownID _town_index;
+
static const SaveLoad _depot_desc[] = {
- SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_VAR(Depot, town_index, SLE_UINT16),
- SLE_END()
+ SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
+ SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
+ SLEG_CONDVAR(_town_index, SLE_UINT16, 0, 140),
+ SLE_CONDREF(Depot, town, REF_TOWN, 141, SL_MAX_VERSION),
+ SLE_CONDVAR(Depot, town_cn, SLE_UINT16, 141, SL_MAX_VERSION),
+ SLE_CONDSTR(Depot, name, SLE_STR, 0, 141, SL_MAX_VERSION),
+ SLE_END()
};
static void Save_DEPT()
@@ -38,9 +44,22 @@ static void Load_DEPT()
while ((index = SlIterateArray()) != -1) {
Depot *depot = new (index) Depot();
SlObject(depot, _depot_desc);
+
+ /* Set the town 'pointer' so we can restore it later. */
+ if (CheckSavegameVersion(141)) depot->town = (Town *)_town_index;
+ }
+}
+
+static void Ptrs_DEPT()
+{
+ Depot *depot;
+
+ FOR_ALL_DEPOTS(depot) {
+ SlObject(depot, _depot_desc);
+ if (CheckSavegameVersion(141)) depot->town = Town::Get((size_t)depot->town);
}
}
extern const ChunkHandler _depot_chunk_handlers[] = {
- { 'DEPT', Save_DEPT, Load_DEPT, NULL, CH_ARRAY | CH_LAST},
+ { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, CH_ARRAY | CH_LAST},
};
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 68c3daf7a..cc49d10b8 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -662,7 +662,7 @@ static bool LoadOldDepot(LoadgameState *ls, int num)
if (!LoadChunk(ls, d, depot_chunk)) return false;
if (d->xy != 0) {
- d->town_index = RemapTownIndex(_old_town_index);
+ d->town = Town::Get(RemapTownIndex(_old_town_index));
} else {
delete d;
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 329ca2a5c..4f48080c2 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -46,7 +46,7 @@
#include "saveload_internal.h"
-extern const uint16 SAVEGAME_VERSION = 140;
+extern const uint16 SAVEGAME_VERSION = 141;
SavegameType _savegame_type; ///< type of savegame we are loading