OpenTTD Source: src/saveload/depot_sl.cpp Source File

OpenTTD Source 1.11.0-RC1

depot_sl.cpp
Go to the documentation of this file.
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 */
7
10 #include "../stdafx.h"
11 #include "../depot_base.h"
12 #include "../town.h"
13
14 #include "saveload.h"
15
16 #include "../safeguards.h"
17
18 static TownID _town_index;
19
20 static const SaveLoad _depot_desc[] = {
21 SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
22 SLE_CONDVAR(Depot, xy, SLE_UINT32, SLV_6, SL_MAX_VERSION),
23 SLEG_CONDVAR(_town_index, SLE_UINT16, SL_MIN_VERSION, SLV_141),
24 SLE_CONDREF(Depot, town, REF_TOWN, SLV_141, SL_MAX_VERSION),
25 SLE_CONDVAR(Depot, town_cn, SLE_UINT16, SLV_141, SL_MAX_VERSION),
26 SLE_CONDSSTR(Depot, name, SLE_STR, SLV_141, SL_MAX_VERSION),
27 SLE_CONDVAR(Depot, build_date, SLE_INT32, SLV_142, SL_MAX_VERSION),
28 SLE_END()
29 };
30
31 static void Save_DEPT()
32 {
33 for (Depot *depot : Depot::Iterate()) {
34 SlSetArrayIndex(depot->index);
35 SlObject(depot, _depot_desc);
36 }
37 }
38
39 static void Load_DEPT()
40 {
41 int index;
42
43 while ((index = SlIterateArray()) != -1) {
44 Depot *depot = new (index) Depot();
45 SlObject(depot, _depot_desc);
46
47 /* Set the town 'pointer' so we can restore it later. */
48 if (IsSavegameVersionBefore(SLV_141)) depot->town = (Town *)(size_t)_town_index;
49 }
50 }
51
52 static void Ptrs_DEPT()
53 {
54 for (Depot *depot : Depot::Iterate()) {
55 SlObject(depot, _depot_desc);
56 if (IsSavegameVersionBefore(SLV_141)) depot->town = Town::Get((size_t)depot->town);
57 }
58 }
59
60 extern const ChunkHandler _depot_chunk_handlers[] = {
61 { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY | CH_LAST},
62 };
Pool::PoolItem<&_town_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
REF_TOWN
@ REF_TOWN
Load/save a reference to a town.
Definition: saveload.h:393
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:593
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:551
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:647
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:410
saveload.h
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:379
SLEG_CONDVAR
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:707
SLV_141
@ SLV_141
141 19799
Definition: saveload.h:212
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:686
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:561
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:815
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SLV_142
@ SLV_142
142 20003
Definition: saveload.h:213
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:328
Pool::PoolItem<&_depot_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
Depot
Definition: depot_base.h:19
Town
Town data structure.
Definition: town.h:50
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631