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/>.
8 /** @file autoreplace_sl.cpp Code handling saving and loading of autoreplace rules */
10 #include "../stdafx.h"
13 #include "compat/autoreplace_sl_compat.h"
15 #include "../autoreplace_base.h"
17 #include "../safeguards.h"
19 static const SaveLoad _engine_renew_desc
[] = {
20 SLE_VAR(EngineRenew
, from
, SLE_UINT16
),
21 SLE_VAR(EngineRenew
, to
, SLE_UINT16
),
23 SLE_REF(EngineRenew
, next
, REF_ENGINE_RENEWS
),
24 SLE_CONDVAR(EngineRenew
, group_id
, SLE_UINT16
, SLV_60
, SL_MAX_VERSION
),
25 SLE_CONDVAR(EngineRenew
, replace_when_old
, SLE_BOOL
, SLV_175
, SL_MAX_VERSION
),
28 struct ERNWChunkHandler
: ChunkHandler
{
29 ERNWChunkHandler() : ChunkHandler('ERNW', CH_TABLE
) {}
31 void Save() const override
33 SlTableHeader(_engine_renew_desc
);
35 for (EngineRenew
*er
: EngineRenew::Iterate()) {
36 SlSetArrayIndex(er
->index
);
37 SlObject(er
, _engine_renew_desc
);
41 void Load() const override
43 const std::vector
<SaveLoad
> slt
= SlCompatTableHeader(_engine_renew_desc
, _engine_renew_sl_compat
);
47 while ((index
= SlIterateArray()) != -1) {
48 EngineRenew
*er
= new (index
) EngineRenew();
51 /* Advanced vehicle lists, ungrouped vehicles got added */
52 if (IsSavegameVersionBefore(SLV_60
)) {
53 er
->group_id
= ALL_GROUP
;
54 } else if (IsSavegameVersionBefore(SLV_71
)) {
55 if (er
->group_id
== DEFAULT_GROUP
) er
->group_id
= ALL_GROUP
;
60 void FixPointers() const override
62 for (EngineRenew
*er
: EngineRenew::Iterate()) {
63 SlObject(er
, _engine_renew_desc
);
68 static const ERNWChunkHandler ERNW
;
69 static const ChunkHandlerRef autoreplace_chunk_handlers
[] = {
73 extern const ChunkHandlerTable
_autoreplace_chunk_handlers(autoreplace_chunk_handlers
);