OpenTTD
subsidy_sl.cpp
Go to the documentation of this file.
1 /* $Id: subsidy_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 "../subsidy_base.h"
14 
15 #include "saveload.h"
16 
17 #include "../safeguards.h"
18 
19 static const SaveLoad _subsidies_desc[] = {
20  SLE_VAR(Subsidy, cargo_type, SLE_UINT8),
21  SLE_VAR(Subsidy, remaining, SLE_UINT8),
22  SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, 125, SL_MAX_VERSION),
23  SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, 125, SL_MAX_VERSION),
24  SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, 125, SL_MAX_VERSION),
25  SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
26  SLE_CONDVAR(Subsidy, src, SLE_UINT16, 5, SL_MAX_VERSION),
27  SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
28  SLE_CONDVAR(Subsidy, dst, SLE_UINT16, 5, SL_MAX_VERSION),
29  SLE_END()
30 };
31 
32 static void Save_SUBS()
33 {
34  Subsidy *s;
35  FOR_ALL_SUBSIDIES(s) {
36  SlSetArrayIndex(s->index);
37  SlObject(s, _subsidies_desc);
38  }
39 }
40 
41 static void Load_SUBS()
42 {
43  int index;
44  while ((index = SlIterateArray()) != -1) {
45  Subsidy *s = new (index) Subsidy();
46  SlObject(s, _subsidies_desc);
47  }
48 }
49 
50 extern const ChunkHandler _subsidy_chunk_handlers[] = {
51  { 'SUBS', Save_SUBS, Load_SUBS, NULL, NULL, CH_ARRAY | CH_LAST},
52 };
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
#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
Struct about subsidies, offered and awarded.
Definition: subsidy_base.h:24
#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
Last chunk in this array.
Definition: saveload.h:104