# depot_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: depot_sl.cpp 21284 2010-11-21 12:47:04Z alberth $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #include "../stdafx.h"
    00013 #include "../depot_base.h"
    00014 #include "../town.h"
    00015
    00016 #include "saveload.h"
    00017
    00018 static TownID _town_index;
    00019
    00020 static const SaveLoad _depot_desc[] = {
    00021    SLE_CONDVAR(Depot, xy,         SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
    00022    SLE_CONDVAR(Depot, xy,         SLE_UINT32,                 6, SL_MAX_VERSION),
    00023   SLEG_CONDVAR(_town_index,       SLE_UINT16,                 0, 140),
    00024    SLE_CONDREF(Depot, town,       REF_TOWN,                 141, SL_MAX_VERSION),
    00025    SLE_CONDVAR(Depot, town_cn,    SLE_UINT16,               141, SL_MAX_VERSION),
    00026    SLE_CONDSTR(Depot, name,       SLE_STR, 0,               141, SL_MAX_VERSION),
    00027    SLE_CONDVAR(Depot, build_date, SLE_INT32,                142, SL_MAX_VERSION),
    00028    SLE_END()
    00029 };
    00030
    00031 static void Save_DEPT()
    00032 {
    00033   Depot *depot;
    00034
    00035   FOR_ALL_DEPOTS(depot) {
    00036     SlSetArrayIndex(depot->index);
    00037     SlObject(depot, _depot_desc);
    00038   }
    00039 }
    00040
    00041 static void Load_DEPT()
    00042 {
    00043   int index;
    00044
    00045   while ((index = SlIterateArray()) != -1) {
    00046     Depot *depot = new (index) Depot();
    00047     SlObject(depot, _depot_desc);
    00048
    00049     /* Set the town 'pointer' so we can restore it later. */
    00050     if (IsSavegameVersionBefore(141)) depot->town = (Town *)(size_t)_town_index;
    00051   }
    00052 }
    00053
    00054 static void Ptrs_DEPT()
    00055 {
    00056   Depot *depot;
    00057
    00058   FOR_ALL_DEPOTS(depot) {
    00059     SlObject(depot, _depot_desc);
    00060     if (IsSavegameVersionBefore(141)) depot->town = Town::Get((size_t)depot->town);
    00061   }
    00062 }
    00063
    00064 extern const ChunkHandler _depot_chunk_handlers[] = {
    00065   { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, NULL, CH_ARRAY | CH_LAST},
    00066 };