OpenTTD Source: src/saveload/group_sl.cpp Source File

OpenTTD Source 1.11.0-RC1

group_sl.cpp
Go to the documentation of this file.
1 /*
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/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../group.h"
12 #include "../company_base.h"
13
14 #include "saveload.h"
15
16 #include "../safeguards.h"
17
18 static const SaveLoad _group_desc[] = {
19 SLE_CONDVAR(Group, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
20 SLE_CONDSSTR(Group, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
21 SLE_CONDNULL(2, SL_MIN_VERSION, SLV_164), // num_vehicle
22 SLE_VAR(Group, owner, SLE_UINT8),
23 SLE_VAR(Group, vehicle_type, SLE_UINT8),
24 SLE_VAR(Group, replace_protection, SLE_BOOL),
25 SLE_CONDVAR(Group, livery.in_use, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
26 SLE_CONDVAR(Group, livery.colour1, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
27 SLE_CONDVAR(Group, livery.colour2, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
28 SLE_CONDVAR(Group, parent, SLE_UINT16, SLV_189, SL_MAX_VERSION),
29 SLE_END()
30 };
31
32 static void Save_GRPS()
33 {
34 for (Group *g : Group::Iterate()) {
35 SlSetArrayIndex(g->index);
36 SlObject(g, _group_desc);
37 }
38 }
39
40
41 static void Load_GRPS()
42 {
43 int index;
44
45 while ((index = SlIterateArray()) != -1) {
46 Group *g = new (index) Group();
47 SlObject(g, _group_desc);
48
49 if (IsSavegameVersionBefore(SLV_189)) g->parent = INVALID_GROUP;
50
51 if (IsSavegameVersionBefore(SLV_GROUP_LIVERIES)) {
52 const Company *c = Company::Get(g->owner);
53 g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
54 g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
55 }
56 }
57 }
58
59 extern const ChunkHandler _group_chunk_handlers[] = {
60 { 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY | CH_LAST},
61 };
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:593
Group::parent
GroupID parent
Parent group.
Definition: group.h:77
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:551
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:143
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:647
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:410
saveload.h
Group::livery
Livery livery
Custom colour scheme for vehicles in this group.
Definition: group.h:72
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:379
SLV_GROUP_LIVERIES
@ SLV_GROUP_LIVERIES
205 PR#7108 Livery storage change and group liveries.
Definition: saveload.h:290
SLE_CONDNULL
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:677
Group
Group data.
Definition: group.h:66
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
allow control codes in the strings
Definition: saveload.h:489
INVALID_GROUP
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
Definition: group_type.h:18
SLV_164
@ SLV_164
164 23290
Definition: saveload.h:239
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:686
Group::owner
Owner owner
Group Owner.
Definition: group.h:68
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:815
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:328
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:621
Pool::PoolItem<&_group_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
SLV_189
@ SLV_189
189 26450 Hierarchical vehicle subgroups
Definition: saveload.h:269
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
Company
Definition: company_base.h:110
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631
Livery::colour2
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
Livery::colour1
byte colour1
First colour, for all vehicles.
Definition: livery.h:80