OpenTTD
subsidy_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 "../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, SLV_125, SL_MAX_VERSION),
23  SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
24  SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
25  SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
26  SLE_CONDVAR(Subsidy, src, SLE_UINT16, SLV_5, SL_MAX_VERSION),
27  SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
28  SLE_CONDVAR(Subsidy, dst, SLE_UINT16, SLV_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 };
125 17113
Definition: saveload.h:194
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
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:44
First savegame version.
Definition: saveload.h:32
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
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:641
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1543
SaveLoad type struct.
Definition: saveload.h:486
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:584
Last chunk in this array.
Definition: saveload.h:381