# object_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: object_sl.cpp 25833 2013-10-12 16:30:42Z frosch $ */
    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 "../object_base.h"
    00014 #include "../object_map.h"
    00015
    00016 #include "saveload.h"
    00017 #include "newgrf_sl.h"
    00018
    00019 static const SaveLoad _object_desc[] = {
    00020       SLE_VAR(Object, location.tile,              SLE_UINT32),
    00021       SLE_VAR(Object, location.w,                 SLE_FILE_U8 | SLE_VAR_U16),
    00022       SLE_VAR(Object, location.h,                 SLE_FILE_U8 | SLE_VAR_U16),
    00023       SLE_REF(Object, town,                       REF_TOWN),
    00024       SLE_VAR(Object, build_date,                 SLE_UINT32),
    00025   SLE_CONDVAR(Object, colour,                     SLE_UINT8,                  148, SL_MAX_VERSION),
    00026   SLE_CONDVAR(Object, view,                       SLE_UINT8,                  155, SL_MAX_VERSION),
    00027   SLE_CONDVAR(Object, type,                       SLE_UINT16,                 186, SL_MAX_VERSION),
    00028
    00029   SLE_END()
    00030 };
    00031
    00032 static void Save_OBJS()
    00033 {
    00034   Object *o;
    00035
    00036   /* Write the objects */
    00037   FOR_ALL_OBJECTS(o) {
    00038     SlSetArrayIndex(o->index);
    00039     SlObject(o, _object_desc);
    00040   }
    00041 }
    00042
    00043 static void Load_OBJS()
    00044 {
    00045   int index;
    00046   while ((index = SlIterateArray()) != -1) {
    00047     Object *o = new (index) Object();
    00048     SlObject(o, _object_desc);
    00049   }
    00050 }
    00051
    00052 static void Ptrs_OBJS()
    00053 {
    00054   Object *o;
    00055   FOR_ALL_OBJECTS(o) {
    00056     SlObject(o, _object_desc);
    00057     if (IsSavegameVersionBefore(148) && !IsTileType(o->location.tile, MP_OBJECT)) {
    00058       /* Due to a small bug stale objects could remain. */
    00059       delete o;
    00060     }
    00061   }
    00062 }
    00063
    00064 static void Save_OBID()
    00065 {
    00066   Save_NewGRFMapping(_object_mngr);
    00067 }
    00068
    00069 static void Load_OBID()
    00070 {
    00071   Load_NewGRFMapping(_object_mngr);
    00072 }
    00073
    00074 extern const ChunkHandler _object_chunk_handlers[] = {
    00075   { 'OBID', Save_OBID, Load_OBID, NULL,      NULL, CH_ARRAY },
    00076   { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, NULL, CH_ARRAY | CH_LAST},
    00077 };