summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-07-16 23:02:39 +0000
committerrubidium <rubidium@openttd.org>2009-07-16 23:02:39 +0000
commit9933df9d89a72bd3b8b6cc23cb1170de3c5a8c4d (patch)
treedc217c4d89a73a6b692f8e0322cc9934deb04f4e /src/saveload
parenta007d609afec5e40d2aef362aca90d3a53580c8d (diff)
downloadopenttd-9933df9d89a72bd3b8b6cc23cb1170de3c5a8c4d.tar.xz
(svn r16855) -Codechange: remove unused 'conversion' stuff from the waypoint struct and make it more similar to Station.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp9
-rw-r--r--src/saveload/saveload.cpp2
-rw-r--r--src/saveload/saveload_internal.h2
-rw-r--r--src/saveload/waypoint_sl.cpp78
4 files changed, 47 insertions, 44 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 66256d12e..a26ef0e6b 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -424,9 +424,6 @@ bool AfterLoadGame()
}
}
- /* Update all waypoints */
- if (CheckSavegameVersion(12)) FixOldWaypoints();
-
if (CheckSavegameVersion(84)) {
FOR_ALL_COMPANIES(c) {
c->name = CopyFromOldName(c->name_1);
@@ -447,12 +444,6 @@ bool AfterLoadGame()
t->name = CopyFromOldName(t->townnametype);
if (t->name != NULL) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
}
-
- Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
- wp->name = CopyFromOldName(wp->string_id);
- wp->string_id = STR_NULL;
- }
}
/* From this point the old names array is cleared. */
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 54f2c451f..8b3178512 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -41,7 +41,7 @@
#include "saveload_internal.h"
-extern const uint16 SAVEGAME_VERSION = 121;
+extern const uint16 SAVEGAME_VERSION = 122;
SavegameType _savegame_type; ///< type of savegame we are loading
diff --git a/src/saveload/saveload_internal.h b/src/saveload/saveload_internal.h
index 0486a796f..21030751a 100644
--- a/src/saveload/saveload_internal.h
+++ b/src/saveload/saveload_internal.h
@@ -16,8 +16,6 @@ StringID RemapOldStringID(StringID s);
char *CopyFromOldName(StringID id);
void ResetOldNames();
-void FixOldWaypoints();
-
void AfterLoadWaypoints();
void AfterLoadVehicles(bool part_of_load);
void AfterLoadStations();
diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp
index 3298e56a9..f51a09485 100644
--- a/src/saveload/waypoint_sl.cpp
+++ b/src/saveload/waypoint_sl.cpp
@@ -10,6 +10,7 @@
#include "table/strings.h"
#include "saveload.h"
+#include "saveload_internal.h"
/**
* Update waypoint graphics id against saved GRFID/localidx.
@@ -34,39 +35,25 @@ void AfterLoadWaypoints()
}
}
-/**
- * Fix savegames which stored waypoints in their old format
- */
-void FixOldWaypoints()
-{
- Waypoint *wp;
-
- /* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */
- FOR_ALL_WAYPOINTS(wp) {
- wp->town_index = ClosestTownFromTile(wp->xy, UINT_MAX)->index;
- wp->town_cn = 0;
- if ((wp->string_id & 0xC000) == 0xC000) {
- wp->town_cn = (wp->string_id >> 8) & 0x3F;
- wp->string_id = STR_NULL;
- }
- }
-}
+static uint16 _waypoint_town_index;
+static StringID _waypoint_string_id;
static const SaveLoad _waypoint_desc[] = {
- SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
- SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION),
- SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION),
- SLE_CONDVAR(Waypoint, town_cn, SLE_FILE_U8 | SLE_VAR_U16, 12, 88),
- SLE_CONDVAR(Waypoint, town_cn, SLE_UINT16, 89, SL_MAX_VERSION),
- SLE_CONDVAR(Waypoint, string_id, SLE_STRINGID, 0, 83),
- SLE_CONDSTR(Waypoint, name, SLE_STR, 0, 84, SL_MAX_VERSION),
- SLE_VAR(Waypoint, delete_ctr, SLE_UINT8),
-
- SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30),
- SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION),
- SLE_CONDVAR(Waypoint, spec.localidx, SLE_UINT8, 3, SL_MAX_VERSION),
- SLE_CONDVAR(Waypoint, spec.grfid, SLE_UINT32, 17, SL_MAX_VERSION),
- SLE_CONDVAR(Waypoint, owner, SLE_UINT8, 101, SL_MAX_VERSION),
+ SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
+ SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION),
+ SLEG_CONDVAR(_waypoint_town_index, SLE_UINT16, 12, 121),
+ SLE_CONDREF(Waypoint, town, REF_TOWN, 122, SL_MAX_VERSION),
+ SLE_CONDVAR(Waypoint, town_cn, SLE_FILE_U8 | SLE_VAR_U16, 12, 88),
+ SLE_CONDVAR(Waypoint, town_cn, SLE_UINT16, 89, SL_MAX_VERSION),
+ SLEG_CONDVAR(_waypoint_string_id, SLE_STRINGID, 0, 83),
+ SLE_CONDSTR(Waypoint, name, SLE_STR, 0, 84, SL_MAX_VERSION),
+ SLE_VAR(Waypoint, delete_ctr, SLE_UINT8),
+
+ SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30),
+ SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION),
+ SLE_CONDVAR(Waypoint, spec.localidx, SLE_UINT8, 3, SL_MAX_VERSION),
+ SLE_CONDVAR(Waypoint, spec.grfid, SLE_UINT32, 17, SL_MAX_VERSION),
+ SLE_CONDVAR(Waypoint, owner, SLE_UINT8, 101, SL_MAX_VERSION),
SLE_END()
};
@@ -86,11 +73,38 @@ static void Load_WAYP()
int index;
while ((index = SlIterateArray()) != -1) {
+ _waypoint_string_id = 0;
+ _waypoint_town_index = 0;
+
Waypoint *wp = new (index) Waypoint();
SlObject(wp, _waypoint_desc);
+
+ if (CheckSavegameVersion(84)) wp->name = (char *)(size_t)_waypoint_string_id;
+ if (CheckSavegameVersion(122)) wp->town = (Town *)(size_t)_waypoint_town_index;
+ }
+}
+
+static void Ptrs_WAYP()
+{
+ Waypoint *wp;
+
+ FOR_ALL_WAYPOINTS(wp) {
+ SlObject(wp, _waypoint_desc);
+
+ StringID sid = (StringID)(size_t)wp->name;
+ if (CheckSavegameVersion(12)) {
+ wp->town_cn = (sid & 0xC000) == 0xC000 ? (sid >> 8) & 0x3F : 0;
+ wp->town = ClosestTownFromTile(wp->xy, UINT_MAX);
+ } else if (CheckSavegameVersion(122)) {
+ /* Only for versions 12 .. 122 */
+ wp->town = Town::Get((size_t)wp->town);
+ }
+ if (CheckSavegameVersion(84)) {
+ wp->name = CopyFromOldName(sid);
+ }
}
}
extern const ChunkHandler _waypoint_chunk_handlers[] = {
- { 'CHKP', Save_WAYP, Load_WAYP, NULL, CH_ARRAY | CH_LAST},
+ { 'CHKP', Save_WAYP, Load_WAYP, Ptrs_WAYP, CH_ARRAY | CH_LAST},
};