summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp42
-rw-r--r--src/saveload/object_sl.cpp57
-rw-r--r--src/saveload/saveload.cpp2
3 files changed, 99 insertions, 2 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 12cbf2e3e..1a2d07cca 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -37,6 +37,7 @@
#include "../signs_func.h"
#include "../aircraft.h"
#include "../object_map.h"
+#include "../object_base.h"
#include "../tree_map.h"
#include "../company_func.h"
#include "../road_cmd.h"
@@ -1838,8 +1839,8 @@ bool AfterLoadGame()
/* Reordering/generalisation of the object bits. */
ObjectType type = GetObjectType(t);
- SetObjectAnimationStage(t, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
- SetObjectOffset(t, type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0);
+ SB(_m[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
+ _m[t].m3 = type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0;
/* Make sure those bits are clear as well! */
_m[t].m4 = 0;
@@ -1847,6 +1848,43 @@ bool AfterLoadGame()
}
}
+ if (CheckSavegameVersion(147) && Object::GetNumItems() == 0) {
+ /* Make real objects for object tiles. */
+ for (TileIndex t = 0; t < map_size; t++) {
+ if (!IsTileType(t, MP_OBJECT)) continue;
+
+ if (Town::GetNumItems() == 0) {
+ /* No towns, so remove all objects! */
+ DoClearSquare(t);
+ } else {
+ uint offset = _m[t].m3;
+
+ /* Also move the animation state. */
+ _m[t].m3 = GB(_m[t].m6, 2, 4);
+ SB(_m[t].m6, 2, 4, 0);
+
+ if (offset == 0) {
+ /* No offset, so make the object. */
+ ObjectType type = GetObjectType(t);
+ int size = type == OBJECT_HQ ? 2 : 1;
+
+ Object *o = new Object();
+ o->location.tile = t;
+ o->location.w = size;
+ o->location.h = size;
+ o->build_date = _date;
+ o->town = type == OBJECT_STATUE ? Town::Get(_m[t].m2) : CalcClosestTownFromTile(t, UINT_MAX);
+ _m[t].m2 = o->index;
+ } else {
+ /* We're at an offset, so get the ID from our "root". */
+ TileIndex northern_tile = t - TileXY(GB(offset, 0, 4), GB(offset, 4, 4));
+ assert(IsTileType(northern_tile, MP_OBJECT));
+ _m[t].m2 = _m[northern_tile].m2;
+ }
+ }
+ }
+ }
+
if (CheckSavegameVersion(113)) {
/* allow_town_roads is added, set it if town_layout wasn't TL_NO_ROADS */
if (_settings_game.economy.town_layout == 0) { // was TL_NO_ROADS
diff --git a/src/saveload/object_sl.cpp b/src/saveload/object_sl.cpp
new file mode 100644
index 000000000..db1ab1e41
--- /dev/null
+++ b/src/saveload/object_sl.cpp
@@ -0,0 +1,57 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file object_sl.cpp Code handling saving and loading of objects */
+
+#include "../stdafx.h"
+#include "../object_base.h"
+
+#include "saveload.h"
+
+static const SaveLoad _object_desc[] = {
+ SLE_VAR(Object, location.tile, SLE_UINT32),
+ SLE_VAR(Object, location.w, SLE_FILE_U8 | SLE_VAR_U16),
+ SLE_VAR(Object, location.h, SLE_FILE_U8 | SLE_VAR_U16),
+ SLE_REF(Object, town, REF_TOWN),
+ SLE_VAR(Object, build_date, SLE_UINT32),
+
+ SLE_END()
+};
+
+static void Save_OBJS()
+{
+ Object *o;
+
+ /* Write the objects */
+ FOR_ALL_OBJECTS(o) {
+ SlSetArrayIndex(o->index);
+ SlObject(o, _object_desc);
+ }
+}
+
+static void Load_OBJS()
+{
+ int index;
+ while ((index = SlIterateArray()) != -1) {
+ Object *o = new (index) Object();
+ SlObject(o, _object_desc);
+ }
+}
+
+static void Ptrs_OBJS()
+{
+ Object *o;
+ FOR_ALL_OBJECTS(o) {
+ SlObject(o, _object_desc);
+ }
+}
+
+extern const ChunkHandler _object_chunk_handlers[] = {
+ { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, NULL, CH_ARRAY | CH_LAST},
+};
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 7a9cd9eee..935ebe61d 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -296,6 +296,7 @@ extern const ChunkHandler _cargopacket_chunk_handlers[];
extern const ChunkHandler _autoreplace_chunk_handlers[];
extern const ChunkHandler _labelmaps_chunk_handlers[];
extern const ChunkHandler _airport_chunk_handlers[];
+extern const ChunkHandler _object_chunk_handlers[];
static const ChunkHandler * const _chunk_handlers[] = {
_gamelog_chunk_handlers,
@@ -324,6 +325,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_autoreplace_chunk_handlers,
_labelmaps_chunk_handlers,
_airport_chunk_handlers,
+ _object_chunk_handlers,
NULL,
};