OpenTTD
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),
25  SLE_CONDVAR(Depot, town_cn, SLE_UINT16, 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 };
141 19799
Definition: saveload.h:211
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:763
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:566
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:544
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
Load/save a reference to a town.
Definition: saveload.h:374
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:534
Highest possible saveload version.
Definition: saveload.h:305
First savegame version.
Definition: saveload.h:30
6.0 1721 6.1 1768
Definition: saveload.h:45
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:637
Handlers and description of chunk.
Definition: saveload.h:356
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:671
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:651
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1546
Town data structure.
Definition: town.h:53
SaveLoad type struct.
Definition: saveload.h:496
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:620
142 20003
Definition: saveload.h:212
Last chunk in this array.
Definition: saveload.h:391