OpenTTD

group_sl.cpp
Go to the documentation of this file.
1 /* $Id: group_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
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
15 #include "saveload.h"
16
17 #include "../safeguards.h"
18
19 static const SaveLoad _group_desc[] = {
20 SLE_CONDVAR(Group, name, SLE_NAME, 0, 83),
21 SLE_CONDSTR(Group, name, SLE_STR | SLF_ALLOW_CONTROL, 0, 84, SL_MAX_VERSION),
22 SLE_CONDNULL(2, 0, 163), // num_vehicle
23 SLE_VAR(Group, owner, SLE_UINT8),
24 SLE_VAR(Group, vehicle_type, SLE_UINT8),
25 SLE_VAR(Group, replace_protection, SLE_BOOL),
26 SLE_CONDVAR(Group, parent, SLE_UINT16, 189, SL_MAX_VERSION),
27 SLE_END()
28 };
29
30 static void Save_GRPS()
31 {
32 Group *g;
33
34 FOR_ALL_GROUPS(g) {
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(189)) g->parent = INVALID_GROUP;
50 }
51 }
52
53 extern const ChunkHandler _group_chunk_handlers[] = {
54 { 'GRPS', Save_GRPS, Load_GRPS, NULL, NULL, CH_ARRAY | CH_LAST},
55 };
SLE_CONDNULL
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:344
SLE_CONDSTR
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:278
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
saveload.h
Functions/types related to saving and loading games.
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:246
SLF_ALLOW_CONTROL
allow control codes in the strings
Definition: saveload.h:184
INVALID_GROUP
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
Definition: group_type.h:20
SL_MAX_VERSION
#define SL_MAX_VERSION
Highest possible savegame version.
Definition: saveload.h:96
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:465
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:828
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:66
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:353
Group::parent
GroupID parent
Parent group.
Definition: group.h:74
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
Group
Group data.
Definition: group.h:66
SaveLoad
SaveLoad type struct.
Definition: saveload.h:208
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:296
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:322
CH_LAST
Last chunk in this array.
Definition: saveload.h:104