OpenTTD
storage_sl.cpp
Go to the documentation of this file.
1 /* $Id$ */
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 "../newgrf_storage.h"
14 #include "saveload.h"
15 
16 #include "../safeguards.h"
17 
19 static const SaveLoad _storage_desc[] = {
20  SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, SLV_6, SL_MAX_VERSION),
23  SLE_END()
24 };
25 
27 static void Load_PSAC()
28 {
29  int index;
30 
31  while ((index = SlIterateArray()) != -1) {
33  PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
34  SlObject(ps, _storage_desc);
35  }
36 }
37 
39 static void Save_PSAC()
40 {
42 
43  /* Write the industries */
44  FOR_ALL_STORAGES(ps) {
45  ps->ClearChanges();
46  SlSetArrayIndex(ps->index);
47  SlObject(ps, _storage_desc);
48  }
49 }
50 
53  { 'PSAC', Save_PSAC, Load_PSAC, NULL, NULL, CH_ARRAY | CH_LAST},
54 };
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
static const SaveLoad _storage_desc[]
Description of the data to save and load in PersistentStorage.
Definition: storage_sl.cpp:19
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:524
const ChunkHandler _persistent_storage_chunk_handlers[]
Chunk handler for persistent storages.
Highest possible saveload version.
Definition: saveload.h:295
Class for pooled persistent storage of data.
6.0 1721 6.1 1768
Definition: saveload.h:47
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:634
Handlers and description of chunk.
Definition: saveload.h:346
static void Load_PSAC()
Load persistent storage data.
Definition: storage_sl.cpp:27
static void Save_PSAC()
Save persistent storage data.
Definition: storage_sl.cpp:39
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:641
201 PR#6885 Extend NewGRF persistant storages.
Definition: saveload.h:286
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of an array in some savegame versions.
Definition: saveload.h:545
void ClearChanges()
Discard temporary changes.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1543
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:216
SaveLoad type struct.
Definition: saveload.h:486
161 22567
Definition: saveload.h:237
Last chunk in this array.
Definition: saveload.h:381