OpenTTD
group_sl.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
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/>.
8  */
9 
12 #include "../stdafx.h"
13 #include "../group.h"
14 #include "../company_base.h"
15 
16 #include "saveload.h"
17 
18 #include "../safeguards.h"
19 
20 static const SaveLoad _group_desc[] = {
21  SLE_CONDVAR(Group, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
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),
31  SLE_END()
32 };
33 
34 static void Save_GRPS()
35 {
36  Group *g;
37 
38  FOR_ALL_GROUPS(g) {
39  SlSetArrayIndex(g->index);
40  SlObject(g, _group_desc);
41  }
42 }
43 
44 
45 static void Load_GRPS()
46 {
47  int index;
48 
49  while ((index = SlIterateArray()) != -1) {
50  Group *g = new (index) Group();
51  SlObject(g, _group_desc);
52 
54 
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;
59  }
60  }
61 }
62 
63 extern const ChunkHandler _group_chunk_handlers[] = {
64  { 'GRPS', Save_GRPS, Load_GRPS, NULL, NULL, CH_ARRAY | CH_LAST},
65 };
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:632
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:753
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:556
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:524
Highest possible saveload version.
Definition: saveload.h:295
205 PR#7108 Livery storage change and group liveries.
Definition: saveload.h:291
allow control codes in the strings
Definition: saveload.h:461
First savegame version.
Definition: saveload.h:32
189 26450 Heirarchical vehicle subgroups
Definition: saveload.h:270
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
Definition: group_type.h:20
84 11822
Definition: saveload.h:144
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:83
164 23290
Definition: saveload.h:240
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:634
Handlers and description of chunk.
Definition: saveload.h:346
Livery livery
Custom colour scheme for vehicles in this group.
Definition: group.h:73
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:641
GroupID parent
Parent group.
Definition: group.h:76
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1543
Group data.
Definition: group.h:67
SaveLoad type struct.
Definition: saveload.h:486
OwnerByte owner
Group Owner.
Definition: group.h:69
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:584
byte colour1
First colour, for all vehicles.
Definition: livery.h:82
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:610
Last chunk in this array.
Definition: saveload.h:381