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 group_sl.cpp Code handling saving and loading of economy data */
|
|
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
|
#include "../group.h"
|
2019-01-31 14:57:44 +01:00
|
|
|
#include "../company_base.h"
|
2009-01-04 16:32:25 +01:00
|
|
|
|
|
|
|
#include "saveload.h"
|
2021-05-30 15:59:40 +02:00
|
|
|
#include "compat/group_sl_compat.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 _group_desc[] = {
|
2019-01-26 02:48:40 +01:00
|
|
|
SLE_CONDVAR(Group, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
|
2020-05-17 23:31:59 +02:00
|
|
|
SLE_CONDSSTR(Group, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
|
2013-01-01 11:52:32 +01:00
|
|
|
SLE_VAR(Group, owner, SLE_UINT8),
|
|
|
|
SLE_VAR(Group, vehicle_type, SLE_UINT8),
|
2019-03-30 00:24:40 +01:00
|
|
|
SLE_VAR(Group, flags, SLE_UINT8),
|
2019-02-01 23:46:12 +01:00
|
|
|
SLE_CONDVAR(Group, livery.in_use, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Group, livery.colour1, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Group, livery.colour2, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
|
2019-01-26 02:48:40 +01:00
|
|
|
SLE_CONDVAR(Group, parent, SLE_UINT16, SLV_189, SL_MAX_VERSION),
|
2024-03-14 18:09:35 +01:00
|
|
|
SLE_CONDVAR(Group, number, SLE_UINT16, SLV_GROUP_NUMBERS, SL_MAX_VERSION),
|
2009-01-04 16:32:25 +01:00
|
|
|
};
|
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
struct GRPSChunkHandler : ChunkHandler {
|
|
|
|
GRPSChunkHandler() : ChunkHandler('GRPS', CH_TABLE) {}
|
2021-05-30 15:59:40 +02:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
void Save() const override
|
|
|
|
{
|
|
|
|
SlTableHeader(_group_desc);
|
|
|
|
|
|
|
|
for (Group *g : Group::Iterate()) {
|
|
|
|
SlSetArrayIndex(g->index);
|
|
|
|
SlObject(g, _group_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(_group_desc, _group_sl_compat);
|
2021-05-30 15:59:40 +02:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
int index;
|
2009-01-04 16:32:25 +01:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
Group *g = new (index) Group();
|
|
|
|
SlObject(g, slt);
|
2014-04-08 23:09:06 +02:00
|
|
|
|
2021-06-07 23:24:37 +02:00
|
|
|
if (IsSavegameVersionBefore(SLV_189)) g->parent = INVALID_GROUP;
|
2019-01-31 14:57:44 +01:00
|
|
|
}
|
2009-01-04 16:32:25 +01: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 GRPSChunkHandler GRPS;
|
2021-06-09 16:23:35 +02:00
|
|
|
static const ChunkHandlerRef group_chunk_handlers[] = {
|
|
|
|
GRPS,
|
2009-01-04 16:32:25 +01:00
|
|
|
};
|
2021-05-02 22:41:34 +02:00
|
|
|
|
|
|
|
extern const ChunkHandlerTable _group_chunk_handlers(group_chunk_handlers);
|