OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

autoreplace_sl.cpp
Go to the documentation of this file.
1 /* $Id: autoreplace_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 "../autoreplace_base.h"
14
15 #include "saveload.h"
16
17 #include "../safeguards.h"
18
19 static const SaveLoad _engine_renew_desc[] = {
20 SLE_VAR(EngineRenew, from, SLE_UINT16),
21 SLE_VAR(EngineRenew, to, SLE_UINT16),
22
23 SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
24 SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),
25 SLE_CONDVAR(EngineRenew, replace_when_old, SLE_BOOL, 175, SL_MAX_VERSION),
26 SLE_END()
27 };
28
29 static void Save_ERNW()
30 {
31 EngineRenew *er;
32
33 FOR_ALL_ENGINE_RENEWS(er) {
34 SlSetArrayIndex(er->index);
35 SlObject(er, _engine_renew_desc);
36 }
37 }
38
39 static void Load_ERNW()
40 {
41 int index;
42
43 while ((index = SlIterateArray()) != -1) {
44 EngineRenew *er = new (index) EngineRenew();
45 SlObject(er, _engine_renew_desc);
46
47 /* Advanced vehicle lists, ungrouped vehicles got added */
48 if (IsSavegameVersionBefore(60)) {
49 er->group_id = ALL_GROUP;
50 } else if (IsSavegameVersionBefore(71)) {
51 if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
52 }
53 }
54 }
55
56 static void Ptrs_ERNW()
57 {
58 EngineRenew *er;
59
60 FOR_ALL_ENGINE_RENEWS(er) {
61 SlObject(er, _engine_renew_desc);
62 }
63 }
64
65 extern const ChunkHandler _autoreplace_chunk_handlers[] = {
66 { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, NULL, CH_ARRAY | CH_LAST},
67 };