OpenTTD Source  1.11.2
subsidy_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 "../subsidy_base.h"
12 
13 #include "saveload.h"
14 
15 #include "../safeguards.h"
16 
17 static const SaveLoad _subsidies_desc[] = {
18  SLE_VAR(Subsidy, cargo_type, SLE_UINT8),
19  SLE_VAR(Subsidy, remaining, SLE_UINT8),
20  SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, SLV_125, SL_MAX_VERSION),
21  SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
22  SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
23  SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
24  SLE_CONDVAR(Subsidy, src, SLE_UINT16, SLV_5, SL_MAX_VERSION),
25  SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
26  SLE_CONDVAR(Subsidy, dst, SLE_UINT16, SLV_5, SL_MAX_VERSION),
27  SLE_END()
28 };
29 
30 static void Save_SUBS()
31 {
32  for (Subsidy *s : Subsidy::Iterate()) {
33  SlSetArrayIndex(s->index);
34  SlObject(s, _subsidies_desc);
35  }
36 }
37 
38 static void Load_SUBS()
39 {
40  int index;
41  while ((index = SlIterateArray()) != -1) {
42  Subsidy *s = new (index) Subsidy();
43  SlObject(s, _subsidies_desc);
44  }
45 }
46 
47 extern const ChunkHandler _subsidy_chunk_handlers[] = {
48  { 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY | CH_LAST},
49 };
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:552
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
SLV_5
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:43
Subsidy
Struct about subsidies, offered and awarded.
Definition: subsidy_base.h:22
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:687
SLV_125
@ SLV_125
125 17113
Definition: saveload.h:193
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:329
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:622
Pool::PoolItem<&_subsidy_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