newgrf_sl.cpp

Go to the documentation of this file.
00001 /* $Id: newgrf_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 "../core/bitmath_func.hpp"
00014 #include "../fios.h"
00015 
00016 #include "saveload.h"
00017 #include "newgrf_sl.h"
00018 
00020 static const SaveLoad _newgrf_mapping_desc[] = {
00021   SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
00022   SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
00023   SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
00024   SLE_END()
00025 };
00026 
00027 void Save_NewGRFMapping(const OverrideManagerBase &mapping)
00028 {
00029   for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
00030     SlSetArrayIndex(i);
00031     SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
00032   }
00033 }
00034 
00035 void Load_NewGRFMapping(OverrideManagerBase &mapping)
00036 {
00037   /* Clear the current mapping stored.
00038    * This will create the manager if ever it is not yet done */
00039   mapping.ResetMapping();
00040 
00041   uint max_id = mapping.GetMaxMapping();
00042 
00043   int index;
00044   while ((index = SlIterateArray()) != -1) {
00045     if ((uint)index >= max_id) break;
00046     SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
00047   }
00048 }
00049 
00050 
00051 static const SaveLoad _grfconfig_desc[] = {
00052       SLE_STR(GRFConfig, filename,         SLE_STR,    0x40),
00053       SLE_VAR(GRFConfig, ident.grfid,      SLE_UINT32),
00054       SLE_ARR(GRFConfig, ident.md5sum,     SLE_UINT8,  16),
00055   SLE_CONDVAR(GRFConfig, version,          SLE_UINT32, 151, SL_MAX_VERSION),
00056       SLE_ARR(GRFConfig, param,            SLE_UINT32, 0x80),
00057       SLE_VAR(GRFConfig, num_params,       SLE_UINT8),
00058   SLE_CONDVAR(GRFConfig, palette,          SLE_UINT8,  101, SL_MAX_VERSION),
00059   SLE_END()
00060 };
00061 
00062 
00063 static void Save_NGRF()
00064 {
00065   int index = 0;
00066 
00067   for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
00068     if (HasBit(c->flags, GCF_STATIC)) continue;
00069     SlSetArrayIndex(index++);
00070     SlObject(c, _grfconfig_desc);
00071   }
00072 }
00073 
00074 
00075 static void Load_NGRF_common(GRFConfig *&grfconfig)
00076 {
00077   ClearGRFConfigList(&grfconfig);
00078   while (SlIterateArray() != -1) {
00079     GRFConfig *c = new GRFConfig();
00080     SlObject(c, _grfconfig_desc);
00081     if (IsSavegameVersionBefore(101)) c->SetSuitablePalette();
00082     AppendToGRFConfigList(&grfconfig, c);
00083   }
00084 }
00085 
00086 static void Load_NGRF()
00087 {
00088   Load_NGRF_common(_grfconfig);
00089 
00090   /* Append static NewGRF configuration */
00091   AppendStaticGRFConfigs(&_grfconfig);
00092 }
00093 
00094 static void Check_NGRF()
00095 {
00096   Load_NGRF_common(_load_check_data.grfconfig);
00097 }
00098 
00099 extern const ChunkHandler _newgrf_chunk_handlers[] = {
00100   { 'NGRF', Save_NGRF, Load_NGRF, NULL, Check_NGRF, CH_ARRAY | CH_LAST }
00101 };

Generated on Thu Jan 20 22:57:39 2011 for OpenTTD by  doxygen 1.6.1