Update: Translations from eints
[openttd-github.git] / src / saveload / storage_sl.cpp
blob4db185e9afc4088c06869ef00c8ff5437969d848
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 storage_sl.cpp Code handling saving and loading of persistent storages. */
10 #include "../stdafx.h"
12 #include "saveload.h"
13 #include "compat/storage_sl_compat.h"
15 #include "../newgrf_storage.h"
17 #include "../safeguards.h"
19 /** Description of the data to save and load in #PersistentStorage. */
20 static const SaveLoad _storage_desc[] = {
21 SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, SLV_6, SL_MAX_VERSION),
22 SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, SLV_161, SLV_EXTEND_PERSISTENT_STORAGE),
23 SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 256, SLV_EXTEND_PERSISTENT_STORAGE, SL_MAX_VERSION),
26 /** Persistent storage data. */
27 struct PSACChunkHandler : ChunkHandler {
28 PSACChunkHandler() : ChunkHandler('PSAC', CH_TABLE) {}
30 void Load() const override
32 const std::vector<SaveLoad> slt = SlCompatTableHeader(_storage_desc, _storage_sl_compat);
34 int index;
36 while ((index = SlIterateArray()) != -1) {
37 assert(PersistentStorage::CanAllocateItem());
38 PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
39 SlObject(ps, slt);
43 void Save() const override
45 SlTableHeader(_storage_desc);
47 /* Write the industries */
48 for (PersistentStorage *ps : PersistentStorage::Iterate()) {
49 ps->ClearChanges();
50 SlSetArrayIndex(ps->index);
51 SlObject(ps, _storage_desc);
56 static const PSACChunkHandler PSAC;
57 static const ChunkHandlerRef persistent_storage_chunk_handlers[] = {
58 PSAC,
61 extern const ChunkHandlerTable _persistent_storage_chunk_handlers(persistent_storage_chunk_handlers);