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 subsidy_sl.cpp Code handling saving and loading of subsidies */
10 #include "../stdafx.h"
13 #include "compat/subsidy_sl_compat.h"
15 #include "../subsidy_base.h"
17 #include "../safeguards.h"
19 static const SaveLoad _subsidies_desc
[] = {
20 SLE_VAR(Subsidy
, cargo_type
, SLE_UINT8
),
21 SLE_CONDVAR(Subsidy
, remaining
, SLE_FILE_U8
| SLE_VAR_U16
, SL_MIN_VERSION
, SLV_CUSTOM_SUBSIDY_DURATION
),
22 SLE_CONDVAR(Subsidy
, remaining
, SLE_UINT16
, SLV_CUSTOM_SUBSIDY_DURATION
, SL_MAX_VERSION
),
23 SLE_CONDVAR(Subsidy
, awarded
, SLE_UINT8
, SLV_125
, SL_MAX_VERSION
),
24 SLE_CONDVAR(Subsidy
, src_type
, SLE_UINT8
, SLV_125
, SL_MAX_VERSION
),
25 SLE_CONDVAR(Subsidy
, dst_type
, SLE_UINT8
, SLV_125
, SL_MAX_VERSION
),
26 SLE_CONDVAR(Subsidy
, src
, SLE_FILE_U8
| SLE_VAR_U16
, SL_MIN_VERSION
, SLV_5
),
27 SLE_CONDVAR(Subsidy
, src
, SLE_UINT16
, SLV_5
, SL_MAX_VERSION
),
28 SLE_CONDVAR(Subsidy
, dst
, SLE_FILE_U8
| SLE_VAR_U16
, SL_MIN_VERSION
, SLV_5
),
29 SLE_CONDVAR(Subsidy
, dst
, SLE_UINT16
, SLV_5
, SL_MAX_VERSION
),
32 struct SUBSChunkHandler
: ChunkHandler
{
33 SUBSChunkHandler() : ChunkHandler('SUBS', CH_TABLE
) {}
35 void Save() const override
37 SlTableHeader(_subsidies_desc
);
39 for (Subsidy
*s
: Subsidy::Iterate()) {
40 SlSetArrayIndex(s
->index
);
41 SlObject(s
, _subsidies_desc
);
45 void Load() const override
47 const std::vector
<SaveLoad
> slt
= SlCompatTableHeader(_subsidies_desc
, _subsidies_sl_compat
);
50 while ((index
= SlIterateArray()) != -1) {
51 Subsidy
*s
= new (index
) Subsidy();
57 static const SUBSChunkHandler SUBS
;
58 static const ChunkHandlerRef subsidy_chunk_handlers
[] = {
62 extern const ChunkHandlerTable
_subsidy_chunk_handlers(subsidy_chunk_handlers
);