Update: Translations from eints
[openttd-github.git] / src / saveload / cheat_sl.cpp
blobef1d43c9cdaa7fea1668ec03253c2484ceb3d5d0
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 */
8 /** @file cheat_sl.cpp Code handling saving and loading of cheats */
10 #include "../stdafx.h"
12 #include "saveload.h"
13 #include "compat/cheat_sl_compat.h"
15 #include "../cheat_type.h"
17 #include "../safeguards.h"
19 static const SaveLoad _cheats_desc[] = {
20 SLE_VAR(Cheats, magic_bulldozer.been_used, SLE_BOOL),
21 SLE_VAR(Cheats, magic_bulldozer.value, SLE_BOOL),
22 SLE_VAR(Cheats, switch_company.been_used, SLE_BOOL),
23 SLE_VAR(Cheats, switch_company.value, SLE_BOOL),
24 SLE_VAR(Cheats, money.been_used, SLE_BOOL),
25 SLE_VAR(Cheats, money.value, SLE_BOOL),
26 SLE_VAR(Cheats, crossing_tunnels.been_used, SLE_BOOL),
27 SLE_VAR(Cheats, crossing_tunnels.value, SLE_BOOL),
28 SLE_VAR(Cheats, no_jetcrash.been_used, SLE_BOOL),
29 SLE_VAR(Cheats, no_jetcrash.value, SLE_BOOL),
30 SLE_VAR(Cheats, change_date.been_used, SLE_BOOL),
31 SLE_VAR(Cheats, change_date.value, SLE_BOOL),
32 SLE_VAR(Cheats, setup_prod.been_used, SLE_BOOL),
33 SLE_VAR(Cheats, setup_prod.value, SLE_BOOL),
34 SLE_VAR(Cheats, edit_max_hl.been_used, SLE_BOOL),
35 SLE_VAR(Cheats, edit_max_hl.value, SLE_BOOL),
36 SLE_CONDVAR(Cheats, station_rating.been_used, SLE_BOOL, SLV_STATION_RATING_CHEAT, SL_MAX_VERSION),
37 SLE_CONDVAR(Cheats, station_rating.value, SLE_BOOL, SLV_STATION_RATING_CHEAT, SL_MAX_VERSION),
41 struct CHTSChunkHandler : ChunkHandler {
42 CHTSChunkHandler() : ChunkHandler('CHTS', CH_TABLE) {}
44 void Save() const override
46 SlTableHeader(_cheats_desc);
48 SlSetArrayIndex(0);
49 SlObject(&_cheats, _cheats_desc);
52 void Load() const override
54 std::vector<SaveLoad> slt = SlCompatTableHeader(_cheats_desc, _cheats_sl_compat);
56 if (IsSavegameVersionBefore(SLV_TABLE_CHUNKS)) {
57 size_t count = SlGetFieldLength();
58 std::vector<SaveLoad> oslt;
60 /* Cheats were added over the years without a savegame bump. They are
61 * stored as 2 SLE_BOOLs per entry. "count" indicates how many SLE_BOOLs
62 * are stored for this savegame. So read only "count" SLE_BOOLs (and in
63 * result "count / 2" cheats). */
64 for (auto &sld : slt) {
65 count--;
66 oslt.push_back(sld);
68 if (count == 0) break;
70 slt = oslt;
73 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
74 SlObject(&_cheats, slt);
75 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many CHTS entries");
79 static const CHTSChunkHandler CHTS;
80 static const ChunkHandlerRef cheat_chunk_handlers[] = {
81 CHTS,
84 extern const ChunkHandlerTable _cheat_chunk_handlers(cheat_chunk_handlers);