OpenTTD
goal_sl.cpp
Go to the documentation of this file.
1 /* $Id: goal_sl.cpp 26593 2014-05-17 17:18:07Z frosch $ */
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 "../goal_base.h"
14 
15 #include "saveload.h"
16 
17 #include "../safeguards.h"
18 
19 static const SaveLoad _goals_desc[] = {
20  SLE_VAR(Goal, company, SLE_FILE_U16 | SLE_VAR_U8),
21  SLE_VAR(Goal, type, SLE_FILE_U16 | SLE_VAR_U8),
22  SLE_VAR(Goal, dst, SLE_UINT32),
25  SLE_CONDVAR(Goal, completed, SLE_BOOL, 182, SL_MAX_VERSION),
26  SLE_END()
27 };
28 
29 static void Save_GOAL()
30 {
31  Goal *s;
32  FOR_ALL_GOALS(s) {
33  SlSetArrayIndex(s->index);
34  SlObject(s, _goals_desc);
35  }
36 }
37 
38 static void Load_GOAL()
39 {
40  int index;
41  while ((index = SlIterateArray()) != -1) {
42  Goal *s = new (index) Goal();
43  SlObject(s, _goals_desc);
44  }
45 }
46 
47 extern const ChunkHandler _goal_chunk_handlers[] = {
48  { 'GOAL', Save_GOAL, Load_GOAL, NULL, NULL, CH_ARRAY | CH_LAST},
49 };
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:278
Struct about goals, current and completed.
Definition: goal_base.h:23
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:246
allow control codes in the strings
Definition: saveload.h:184
#define SL_MAX_VERSION
Highest possible savegame version.
Definition: saveload.h:96
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:828
Handlers and description of chunk.
Definition: saveload.h:66
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:353
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SaveLoad type struct.
Definition: saveload.h:208
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:296
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:322
Last chunk in this array.
Definition: saveload.h:104