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"
|
|
|
|
|
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),
|
2019-01-26 02:48:40 +01:00
|
|
|
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_164), // num_vehicle
|
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),
|
2009-01-04 16:32:25 +01:00
|
|
|
};
|
|
|
|
|
2009-05-22 00:43:25 +02:00
|
|
|
static void Save_GRPS()
|
2009-01-04 16:32:25 +01:00
|
|
|
{
|
2019-12-16 18:01:57 +01:00
|
|
|
for (Group *g : Group::Iterate()) {
|
2009-01-04 16:32:25 +01:00
|
|
|
SlSetArrayIndex(g->index);
|
|
|
|
SlObject(g, _group_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 00:43:25 +02:00
|
|
|
static void Load_GRPS()
|
2009-01-04 16:32:25 +01:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
Group *g = new (index) Group();
|
|
|
|
SlObject(g, _group_desc);
|
2014-04-08 23:09:06 +02:00
|
|
|
|
2019-01-26 02:48:40 +01:00
|
|
|
if (IsSavegameVersionBefore(SLV_189)) g->parent = INVALID_GROUP;
|
2019-01-31 14:57:44 +01:00
|
|
|
|
2019-02-01 23:46:12 +01:00
|
|
|
if (IsSavegameVersionBefore(SLV_GROUP_LIVERIES)) {
|
2019-01-31 14:57:44 +01:00
|
|
|
const Company *c = Company::Get(g->owner);
|
|
|
|
g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
|
|
|
|
g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
|
|
|
|
}
|
2009-01-04 16:32:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 22:41:34 +02:00
|
|
|
static const ChunkHandler group_chunk_handlers[] = {
|
|
|
|
{ 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY },
|
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);
|