OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

object_sl.cpp
Go to the documentation of this file.
1 /* $Id: object_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
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/>.
8 */
9
12 #include "../stdafx.h"
13 #include "../object_base.h"
14 #include "../object_map.h"
15
16 #include "saveload.h"
17 #include "newgrf_sl.h"
18
19 #include "../safeguards.h"
20
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),
30
31 SLE_END()
32 };
33
34 static void Save_OBJS()
35 {
36 Object *o;
37
38 /* Write the objects */
39 FOR_ALL_OBJECTS(o) {
40 SlSetArrayIndex(o->index);
41 SlObject(o, _object_desc);
42 }
43 }
44
45 static void Load_OBJS()
46 {
47 int index;
48 while ((index = SlIterateArray()) != -1) {
49 Object *o = new (index) Object();
50 SlObject(o, _object_desc);
51 }
52 }
53
54 static void Ptrs_OBJS()
55 {
56 Object *o;
57 FOR_ALL_OBJECTS(o) {
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. */
61 delete o;
62 }
63 }
64 }
65
66 static void Save_OBID()
67 {
68 Save_NewGRFMapping(_object_mngr);
69 }
70
71 static void Load_OBID()
72 {
73 Load_NewGRFMapping(_object_mngr);
74 }
75
76 extern const ChunkHandler _object_chunk_handlers[] = {
77 { 'OBID', Save_OBID, Load_OBID, NULL, NULL, CH_ARRAY },
78 { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, NULL, CH_ARRAY | CH_LAST},
79 };