OpenTTD
depot_sl.cpp
Go to the documentation of this file.
1 /* $Id: depot_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 "../depot_base.h"
14 #include "../town.h"
15 
16 #include "saveload.h"
17 
18 #include "../safeguards.h"
19 
20 static TownID _town_index;
21 
22 static const SaveLoad _depot_desc[] = {
23  SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
24  SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
25  SLEG_CONDVAR(_town_index, SLE_UINT16, 0, 140),
27  SLE_CONDVAR(Depot, town_cn, SLE_UINT16, 141, SL_MAX_VERSION),
28  SLE_CONDSTR(Depot, name, SLE_STR, 0, 141, SL_MAX_VERSION),
29  SLE_CONDVAR(Depot, build_date, SLE_INT32, 142, SL_MAX_VERSION),
30  SLE_END()
31 };
32 
33 static void Save_DEPT()
34 {
35  Depot *depot;
36 
37  FOR_ALL_DEPOTS(depot) {
38  SlSetArrayIndex(depot->index);
39  SlObject(depot, _depot_desc);
40  }
41 }
42 
43 static void Load_DEPT()
44 {
45  int index;
46 
47  while ((index = SlIterateArray()) != -1) {
48  Depot *depot = new (index) Depot();
49  SlObject(depot, _depot_desc);
50 
51  /* Set the town 'pointer' so we can restore it later. */
52  if (IsSavegameVersionBefore(141)) depot->town = (Town *)(size_t)_town_index;
53  }
54 }
55 
56 static void Ptrs_DEPT()
57 {
58  Depot *depot;
59 
60  FOR_ALL_DEPOTS(depot) {
61  SlObject(depot, _depot_desc);
62  if (IsSavegameVersionBefore(141)) depot->town = Town::Get((size_t)depot->town);
63  }
64 }
65 
66 extern const ChunkHandler _depot_chunk_handlers[] = {
67  { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, NULL, CH_ARRAY | CH_LAST},
68 };