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/>.
8 /** @file depot_sl.cpp Code handling saving and loading of depots */
10 #include "../stdafx.h"
13 #include "compat/depot_sl_compat.h"
15 #include "../depot_base.h"
18 #include "../safeguards.h"
20 static TownID _town_index
;
22 static const SaveLoad _depot_desc
[] = {
23 SLE_CONDVAR(Depot
, xy
, SLE_FILE_U16
| SLE_VAR_U32
, SL_MIN_VERSION
, SLV_6
),
24 SLE_CONDVAR(Depot
, xy
, SLE_UINT32
, SLV_6
, SL_MAX_VERSION
),
25 SLEG_CONDVAR("town_index", _town_index
, SLE_UINT16
, SL_MIN_VERSION
, SLV_141
),
26 SLE_CONDREF(Depot
, town
, REF_TOWN
, SLV_141
, SL_MAX_VERSION
),
27 SLE_CONDVAR(Depot
, town_cn
, SLE_UINT16
, SLV_141
, SL_MAX_VERSION
),
28 SLE_CONDSSTR(Depot
, name
, SLE_STR
, SLV_141
, SL_MAX_VERSION
),
29 SLE_CONDVAR(Depot
, build_date
, SLE_INT32
, SLV_142
, SL_MAX_VERSION
),
32 struct DEPTChunkHandler
: ChunkHandler
{
33 DEPTChunkHandler() : ChunkHandler('DEPT', CH_TABLE
) {}
35 void Save() const override
37 SlTableHeader(_depot_desc
);
39 for (Depot
*depot
: Depot::Iterate()) {
40 SlSetArrayIndex(depot
->index
);
41 SlObject(depot
, _depot_desc
);
45 void Load() const override
47 const std::vector
<SaveLoad
> slt
= SlCompatTableHeader(_depot_desc
, _depot_sl_compat
);
51 while ((index
= SlIterateArray()) != -1) {
52 Depot
*depot
= new (index
) Depot();
55 /* Set the town 'pointer' so we can restore it later. */
56 if (IsSavegameVersionBefore(SLV_141
)) depot
->town
= (Town
*)(size_t)_town_index
;
60 void FixPointers() const override
62 for (Depot
*depot
: Depot::Iterate()) {
63 SlObject(depot
, _depot_desc
);
64 if (IsSavegameVersionBefore(SLV_141
)) depot
->town
= Town::Get((size_t)depot
->town
);
69 static const DEPTChunkHandler DEPT
;
70 static const ChunkHandlerRef depot_chunk_handlers
[] = {
74 extern const ChunkHandlerTable
_depot_chunk_handlers(depot_chunk_handlers
);