OpenTTD
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);
60  /* Due to a small bug stale objects could remain. */
61  delete o;
62  }
63  }
64 }
65 
66 static void Save_OBID()
67 {
69 }
70 
71 static void Load_OBID()
72 {
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 };
Code handling saving and loading of NewGRF mappings.
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:304
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Load/save a reference to a town.
Definition: saveload.h:84
Contains objects such as transmitters and owned land.
Definition: tile_type.h:53
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:246
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
An object, such as transmitter, on the map.
Definition: object_base.h:25
#define SL_MAX_VERSION
Highest possible savegame version.
Definition: saveload.h:96
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:465
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:828
Handlers and description of chunk.
Definition: saveload.h:66
void Load_NewGRFMapping(OverrideManagerBase &mapping)
Load a GRF ID + local id -> OpenTTD&#39;s id mapping.
Definition: newgrf_sl.cpp:44
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:353
TileArea location
Location of the object.
Definition: object_base.h:28
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SaveLoad type struct.
Definition: saveload.h:208
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:296
void Save_NewGRFMapping(const OverrideManagerBase &mapping)
Save a GRF ID + local id -> OpenTTD&#39;s id mapping.
Definition: newgrf_sl.cpp:32
ObjectOverrideManager _object_mngr
The override manager for our objects.
Last chunk in this array.
Definition: saveload.h:104