OpenTTD Source  1.11.2
goal_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 "../goal_base.h"
12 
13 #include "saveload.h"
14 
15 #include "../safeguards.h"
16 
17 static const SaveLoad _goals_desc[] = {
18  SLE_VAR(Goal, company, SLE_FILE_U16 | SLE_VAR_U8),
19  SLE_VAR(Goal, type, SLE_FILE_U16 | SLE_VAR_U8),
20  SLE_VAR(Goal, dst, SLE_UINT32),
23  SLE_CONDVAR(Goal, completed, SLE_BOOL, SLV_182, SL_MAX_VERSION),
24  SLE_END()
25 };
26 
27 static void Save_GOAL()
28 {
29  for (Goal *s : Goal::Iterate()) {
30  SlSetArrayIndex(s->index);
31  SlObject(s, _goals_desc);
32  }
33 }
34 
35 static void Load_GOAL()
36 {
37  int index;
38  while ((index = SlIterateArray()) != -1) {
39  Goal *s = new (index) Goal();
40  SlObject(s, _goals_desc);
41  }
42 }
43 
44 extern const ChunkHandler _goal_chunk_handlers[] = {
45  { 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY | CH_LAST},
46 };
Goal
Struct about goals, current and completed.
Definition: goal_base.h:21
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:552
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:648
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:411
saveload.h
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:380
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
allow control codes in the strings
Definition: saveload.h:490
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:687
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SLV_182
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:261
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:329
SLE_CONDSTR
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:584
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:622
Pool::PoolItem<&_goal_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
SaveLoad
SaveLoad type struct.
Definition: saveload.h:517
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631