4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file group_sl.cpp Code handling saving and loading of economy data */
12 #include "../stdafx.h"
14 #include "../company_base.h"
18 #include "../safeguards.h"
20 static const SaveLoad _group_desc
[] = {
21 SLE_CONDVAR(Group
, name
, SLE_NAME
, SL_MIN_VERSION
, SLV_84
),
22 SLE_CONDSTR(Group
, name
, SLE_STR
| SLF_ALLOW_CONTROL
, 0, SLV_84
, SL_MAX_VERSION
),
23 SLE_CONDNULL(2, SL_MIN_VERSION
, SLV_164
), // num_vehicle
24 SLE_VAR(Group
, owner
, SLE_UINT8
),
25 SLE_VAR(Group
, vehicle_type
, SLE_UINT8
),
26 SLE_VAR(Group
, replace_protection
, SLE_BOOL
),
27 SLE_CONDVAR(Group
, livery
.in_use
, SLE_UINT8
, SLV_GROUP_LIVERIES
, SL_MAX_VERSION
),
28 SLE_CONDVAR(Group
, livery
.colour1
, SLE_UINT8
, SLV_GROUP_LIVERIES
, SL_MAX_VERSION
),
29 SLE_CONDVAR(Group
, livery
.colour2
, SLE_UINT8
, SLV_GROUP_LIVERIES
, SL_MAX_VERSION
),
30 SLE_CONDVAR(Group
, parent
, SLE_UINT16
, SLV_189
, SL_MAX_VERSION
),
34 static void Save_GRPS()
39 SlSetArrayIndex(g
->index
);
40 SlObject(g
, _group_desc
);
45 static void Load_GRPS()
49 while ((index
= SlIterateArray()) != -1) {
50 Group
*g
= new (index
) Group();
51 SlObject(g
, _group_desc
);
53 if (IsSavegameVersionBefore(SLV_189
)) g
->parent
= INVALID_GROUP
;
55 if (IsSavegameVersionBefore(SLV_GROUP_LIVERIES
)) {
56 const Company
*c
= Company::Get(g
->owner
);
57 g
->livery
.colour1
= c
->livery
[LS_DEFAULT
].colour1
;
58 g
->livery
.colour2
= c
->livery
[LS_DEFAULT
].colour2
;
63 extern const ChunkHandler _group_chunk_handlers
[] = {
64 { 'GRPS', Save_GRPS
, Load_GRPS
, nullptr, nullptr, CH_ARRAY
| CH_LAST
},