Fix some daylength issues, possible division by zero in main menu.
[openttd-joker.git] / src / saveload / depot_sl.cpp
blobd84659119940aaf2e3ac8894c391115ef252c322
1 /* $Id: depot_sl.cpp 21284 2010-11-21 12:47:04Z alberth $ */
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 */
10 /** @file depot_sl.cpp Code handling saving and loading of depots */
12 #include "../stdafx.h"
13 #include "../depot_base.h"
14 #include "../town.h"
16 #include "saveload.h"
18 #include "../safeguards.h"
20 static TownID _town_index;
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),
26 SLE_CONDREF(Depot, town, REF_TOWN, 141, SL_MAX_VERSION),
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()
33 static void Save_DEPT()
35 Depot *depot;
37 FOR_ALL_DEPOTS(depot) {
38 SlSetArrayIndex(depot->index);
39 SlObject(depot, _depot_desc);
43 static void Load_DEPT()
45 int index;
47 while ((index = SlIterateArray()) != -1) {
48 Depot *depot = new (index) Depot();
49 SlObject(depot, _depot_desc);
51 /* Set the town 'pointer' so we can restore it later. */
52 if (IsSavegameVersionBefore(141)) depot->town = (Town *)(size_t)_town_index;
56 static void Ptrs_DEPT()
58 Depot *depot;
60 FOR_ALL_DEPOTS(depot) {
61 SlObject(depot, _depot_desc);
62 if (IsSavegameVersionBefore(141)) depot->town = Town::Get((size_t)depot->town);
66 extern const ChunkHandler _depot_chunk_handlers[] = {
67 { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, NULL, CH_ARRAY | CH_LAST},