1 /* $Id: object_sl.cpp 25833 2013-10-12 16:30:42Z frosch $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file object_sl.cpp Code handling saving and loading of objects */
12 #include "../stdafx.h"
13 #include "../object_base.h"
14 #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
, 148, SL_MAX_VERSION
),
28 SLE_CONDVAR(Object
, view
, SLE_UINT8
, 155, SL_MAX_VERSION
),
29 SLE_CONDVAR(Object
, type
, SLE_UINT16
, 186, SL_MAX_VERSION
),
34 static void Save_OBJS()
38 /* Write the objects */
40 SlSetArrayIndex(o
->index
);
41 SlObject(o
, _object_desc
);
45 static void Load_OBJS()
48 while ((index
= SlIterateArray()) != -1) {
49 Object
*o
= new (index
) Object();
50 SlObject(o
, _object_desc
);
54 static void Ptrs_OBJS()
58 SlObject(o
, _object_desc
);
59 if (IsSavegameVersionBefore(148) && !IsTileType(o
->location
.tile
, MP_OBJECT
)) {
60 /* Due to a small bug stale objects could remain. */
66 static void Save_OBID()
68 Save_NewGRFMapping(_object_mngr
);
71 static void Load_OBID()
73 Load_NewGRFMapping(_object_mngr
);
76 extern const ChunkHandler _object_chunk_handlers
[] = {
77 { 'OBID', Save_OBID
, Load_OBID
, nullptr, nullptr, CH_ARRAY
},
78 { 'OBJS', Save_OBJS
, Load_OBJS
, Ptrs_OBJS
, nullptr, CH_ARRAY
| CH_LAST
},