OpenTTD

depot_sl.cpp
Go to the documentation of this file.
1 /* $Id: depot_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 "../depot_base.h"
14 #include "../town.h"
15
16 #include "saveload.h"
17
18 #include "../safeguards.h"
19
20 static TownID _town_index;
21
22 static const SaveLoad _depot_desc[] = {
23 SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
24 SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
25 SLEG_CONDVAR(_town_index, SLE_UINT16, 0, 140),
26 SLE_CONDREF(Depot, town, REF_TOWN, 141, SL_MAX_VERSION),
27 SLE_CONDVAR(Depot, town_cn, SLE_UINT16, 141, SL_MAX_VERSION),
28 SLE_CONDSTR(Depot, name, SLE_STR, 0, 141, SL_MAX_VERSION),
29 SLE_CONDVAR(Depot, build_date, SLE_INT32, 142, SL_MAX_VERSION),
30 SLE_END()
31 };
32
33 static void Save_DEPT()
34 {
35 Depot *depot;
36
37 FOR_ALL_DEPOTS(depot) {
38 SlSetArrayIndex(depot->index);
39 SlObject(depot, _depot_desc);
40 }
41 }
42
43 static void Load_DEPT()
44 {
45 int index;
46
47 while ((index = SlIterateArray()) != -1) {
48 Depot *depot = new (index) Depot();
49 SlObject(depot, _depot_desc);
50
51 /* Set the town 'pointer' so we can restore it later. */
52 if (IsSavegameVersionBefore(141)) depot->town = (Town *)(size_t)_town_index;
53 }
54 }
55
56 static void Ptrs_DEPT()
57 {
58 Depot *depot;
59
60 FOR_ALL_DEPOTS(depot) {
61 SlObject(depot, _depot_desc);
62 if (IsSavegameVersionBefore(141)) depot->town = Town::Get((size_t)depot->town);
63 }
64 }
65
66 extern const ChunkHandler _depot_chunk_handlers[] = {
67 { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, NULL, CH_ARRAY | CH_LAST},
68 };
SLE_CONDSTR
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:278
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:256
Pool::PoolItem<&_town_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
REF_TOWN
Load/save a reference to a town.
Definition: saveload.h:84
saveload.h
Functions/types related to saving and loading games.
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:246
SL_MAX_VERSION
#define SL_MAX_VERSION
Highest possible savegame version.
Definition: saveload.h:96
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:465
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:828
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:66
SLEG_CONDVAR
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:373
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:353
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
Town
Town data structure.
Definition: town.h:55
SaveLoad
SaveLoad type struct.
Definition: saveload.h:208
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:322
Depot
Definition: depot_base.h:21
CH_LAST
Last chunk in this array.
Definition: saveload.h:104