2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-01-04 16:32:25 +01:00
|
|
|
/** @file subsidy_sl.cpp Code handling saving and loading of subsidies */
|
|
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
|
|
|
|
|
#include "saveload.h"
|
2021-05-30 15:59:40 +02:00
|
|
|
#include "compat/subsidy_sl_compat.h"
|
|
|
|
|
|
|
|
#include "../subsidy_base.h"
|
2009-01-04 16:32:25 +01:00
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2009-01-04 16:32:25 +01:00
|
|
|
static const SaveLoad _subsidies_desc[] = {
|
|
|
|
SLE_VAR(Subsidy, cargo_type, SLE_UINT8),
|
2021-04-22 19:54:32 +02:00
|
|
|
SLE_CONDVAR(Subsidy, remaining, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_CUSTOM_SUBSIDY_DURATION),
|
|
|
|
SLE_CONDVAR(Subsidy, remaining, SLE_UINT16, SLV_CUSTOM_SUBSIDY_DURATION, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, SLV_125, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
|
|
|
|
SLE_CONDVAR(Subsidy, src, SLE_UINT16, SLV_5, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
|
|
|
|
SLE_CONDVAR(Subsidy, dst, SLE_UINT16, SLV_5, SL_MAX_VERSION),
|
2009-01-04 16:32:25 +01:00
|
|
|
};
|
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
struct SUBSChunkHandler : ChunkHandler {
|
|
|
|
SUBSChunkHandler() : ChunkHandler('SUBS', CH_TABLE) {}
|
2021-05-30 15:59:40 +02:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
void Save() const override
|
|
|
|
{
|
|
|
|
SlTableHeader(_subsidies_desc);
|
|
|
|
|
|
|
|
for (Subsidy *s : Subsidy::Iterate()) {
|
|
|
|
SlSetArrayIndex(s->index);
|
|
|
|
SlObject(s, _subsidies_desc);
|
|
|
|
}
|
2009-01-04 16:32:25 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
void Load() const override
|
|
|
|
{
|
|
|
|
const std::vector<SaveLoad> slt = SlCompatTableHeader(_subsidies_desc, _subsidies_sl_compat);
|
2021-05-30 15:59:40 +02:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
int index;
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
Subsidy *s = new (index) Subsidy();
|
|
|
|
SlObject(s, slt);
|
|
|
|
}
|
2009-07-01 20:45:05 +02:00
|
|
|
}
|
2021-06-07 23:24:37 +02:00
|
|
|
};
|
2009-01-04 16:32:25 +01:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
static const SUBSChunkHandler SUBS;
|
2021-06-09 16:23:35 +02:00
|
|
|
static const ChunkHandlerRef subsidy_chunk_handlers[] = {
|
|
|
|
SUBS,
|
2009-01-04 16:32:25 +01:00
|
|
|
};
|
2021-05-02 22:41:34 +02:00
|
|
|
|
|
|
|
extern const ChunkHandlerTable _subsidy_chunk_handlers(subsidy_chunk_handlers);
|