OpenTTD Source: src/saveload/autoreplace_sl.cpp Source File

OpenTTD Source 1.11.0-RC1

autoreplace_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 "../autoreplace_base.h"
12
13 #include "saveload.h"
14
15 #include "../safeguards.h"
16
17 static const SaveLoad _engine_renew_desc[] = {
18 SLE_VAR(EngineRenew, from, SLE_UINT16),
19 SLE_VAR(EngineRenew, to, SLE_UINT16),
20
21 SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
22 SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
23 SLE_CONDVAR(EngineRenew, replace_when_old, SLE_BOOL, SLV_175, SL_MAX_VERSION),
24 SLE_END()
25 };
26
27 static void Save_ERNW()
28 {
29 for (EngineRenew *er : EngineRenew::Iterate()) {
30 SlSetArrayIndex(er->index);
31 SlObject(er, _engine_renew_desc);
32 }
33 }
34
35 static void Load_ERNW()
36 {
37 int index;
38
39 while ((index = SlIterateArray()) != -1) {
40 EngineRenew *er = new (index) EngineRenew();
41 SlObject(er, _engine_renew_desc);
42
43 /* Advanced vehicle lists, ungrouped vehicles got added */
44 if (IsSavegameVersionBefore(SLV_60)) {
45 er->group_id = ALL_GROUP;
46 } else if (IsSavegameVersionBefore(SLV_71)) {
47 if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
48 }
49 }
50 }
51
52 static void Ptrs_ERNW()
53 {
54 for (EngineRenew *er : EngineRenew::Iterate()) {
55 SlObject(er, _engine_renew_desc);
56 }
57 }
58
59 extern const ChunkHandler _autoreplace_chunk_handlers[] = {
60 { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY | CH_LAST},
61 };
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:551
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:410
saveload.h
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:379
SLV_175
@ SLV_175
175 24136
Definition: saveload.h:253
SLE_REF
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:629
ALL_GROUP
static const GroupID ALL_GROUP
All vehicles are in this group.
Definition: group_type.h:16
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:686
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:815
REF_ENGINE_RENEWS
@ REF_ENGINE_RENEWS
Load/save a reference to an engine renewal (autoreplace).
Definition: saveload.h:396
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
EngineRenew
Struct to store engine replacements.
Definition: autoreplace_base.h:33
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:328
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:621
Pool::PoolItem<&_enginerenew_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
SLV_60
@ SLV_60
60 9874
Definition: saveload.h:115
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631
SLV_71
@ SLV_71
71 10567
Definition: saveload.h:128