object_sl.cpp

Go to the documentation of this file.
00001 /* $Id$ */
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 
00028   SLE_END()
00029 };
00030 
00031 static void Save_OBJS()
00032 {
00033   Object *o;
00034 
00035   /* Write the objects */
00036   FOR_ALL_OBJECTS(o) {
00037     SlSetArrayIndex(o->index);
00038     SlObject(o, _object_desc);
00039   }
00040 }
00041 
00042 static void Load_OBJS()
00043 {
00044   int index;
00045   while ((index = SlIterateArray()) != -1) {
00046     Object *o = new (index) Object();
00047     SlObject(o, _object_desc);
00048   }
00049 }
00050 
00051 static void Ptrs_OBJS()
00052 {
00053   Object *o;
00054   FOR_ALL_OBJECTS(o) {
00055     SlObject(o, _object_desc);
00056     if (IsSavegameVersionBefore(148) && !IsTileType(o->location.tile, MP_OBJECT)) {
00057       /* Due to a small bug stale objects could remain. */
00058       delete o;
00059     } else {
00060       Object::IncTypeCount(GetObjectType(o->location.tile));
00061     }
00062   }
00063 }
00064 
00065 static void Save_OBID()
00066 {
00067   Save_NewGRFMapping(_object_mngr);
00068 }
00069 
00070 static void Load_OBID()
00071 {
00072   Load_NewGRFMapping(_object_mngr);
00073 }
00074 
00075 extern const ChunkHandler _object_chunk_handlers[] = {
00076   { 'OBID', Save_OBID, Load_OBID, NULL,      NULL, CH_ARRAY },
00077   { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, NULL, CH_ARRAY | CH_LAST},
00078 };

Generated on Fri May 27 04:19:47 2011 for OpenTTD by  doxygen 1.6.1