Update: Translations from eints
[openttd-github.git] / src / saveload / object_sl.cpp
blobeea1ec0fcbc8f6cc31ca8722782293418048c8c7
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file object_sl.cpp Code handling saving and loading of objects */
10 #include "../stdafx.h"
12 #include "saveload.h"
13 #include "compat/object_sl_compat.h"
15 #include "../object_base.h"
16 #include "../object_map.h"
17 #include "newgrf_sl.h"
19 #include "../safeguards.h"
21 static const SaveLoad _object_desc[] = {
22 SLE_VAR(Object, location.tile, SLE_UINT32),
23 SLE_VAR(Object, location.w, SLE_FILE_U8 | SLE_VAR_U16),
24 SLE_VAR(Object, location.h, SLE_FILE_U8 | SLE_VAR_U16),
25 SLE_REF(Object, town, REF_TOWN),
26 SLE_VAR(Object, build_date, SLE_UINT32),
27 SLE_CONDVAR(Object, colour, SLE_UINT8, SLV_148, SL_MAX_VERSION),
28 SLE_CONDVAR(Object, view, SLE_UINT8, SLV_155, SL_MAX_VERSION),
29 SLE_CONDVAR(Object, type, SLE_UINT16, SLV_186, SL_MAX_VERSION),
32 struct OBJSChunkHandler : ChunkHandler {
33 OBJSChunkHandler() : ChunkHandler('OBJS', CH_TABLE) {}
35 void Save() const override
37 SlTableHeader(_object_desc);
39 /* Write the objects */
40 for (Object *o : Object::Iterate()) {
41 SlSetArrayIndex(o->index);
42 SlObject(o, _object_desc);
46 void Load() const override
48 const std::vector<SaveLoad> slt = SlCompatTableHeader(_object_desc, _object_sl_compat);
50 int index;
51 while ((index = SlIterateArray()) != -1) {
52 Object *o = new (index) Object();
53 SlObject(o, slt);
57 void FixPointers() const override
59 for (Object *o : Object::Iterate()) {
60 SlObject(o, _object_desc);
61 if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) {
62 /* Due to a small bug stale objects could remain. */
63 delete o;
69 struct OBIDChunkHandler : NewGRFMappingChunkHandler {
70 OBIDChunkHandler() : NewGRFMappingChunkHandler('OBID', _object_mngr) {}
73 static const OBIDChunkHandler OBID;
74 static const OBJSChunkHandler OBJS;
75 static const ChunkHandlerRef object_chunk_handlers[] = {
76 OBID,
77 OBJS,
80 extern const ChunkHandlerTable _object_chunk_handlers(object_chunk_handlers);