# newgrf_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 "../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
    00031 void Save_NewGRFMapping(const OverrideManagerBase &mapping)
    00032 {
    00033   for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
    00034     SlSetArrayIndex(i);
    00035     SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
    00036   }
    00037 }
    00038
    00043 void Load_NewGRFMapping(OverrideManagerBase &mapping)
    00044 {
    00045   /* Clear the current mapping stored.
    00046    * This will create the manager if ever it is not yet done */
    00047   mapping.ResetMapping();
    00048
    00049   uint max_id = mapping.GetMaxMapping();
    00050
    00051   int index;
    00052   while ((index = SlIterateArray()) != -1) {
    00053     if ((uint)index >= max_id) break;
    00054     SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
    00055   }
    00056 }
    00057
    00058
    00059 static const SaveLoad _grfconfig_desc[] = {
    00060       SLE_STR(GRFConfig, filename,         SLE_STR,    0x40),
    00061       SLE_VAR(GRFConfig, ident.grfid,      SLE_UINT32),
    00062       SLE_ARR(GRFConfig, ident.md5sum,     SLE_UINT8,  16),
    00063   SLE_CONDVAR(GRFConfig, version,          SLE_UINT32, 151, SL_MAX_VERSION),
    00064       SLE_ARR(GRFConfig, param,            SLE_UINT32, 0x80),
    00065       SLE_VAR(GRFConfig, num_params,       SLE_UINT8),
    00066   SLE_CONDVAR(GRFConfig, palette,          SLE_UINT8,  101, SL_MAX_VERSION),
    00067   SLE_END()
    00068 };
    00069
    00070
    00071 static void Save_NGRF()
    00072 {
    00073   int index = 0;
    00074
    00075   for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
    00076     if (HasBit(c->flags, GCF_STATIC)) continue;
    00077     SlSetArrayIndex(index++);
    00078     SlObject(c, _grfconfig_desc);
    00079   }
    00080 }
    00081
    00082
    00083 static void Load_NGRF_common(GRFConfig *&grfconfig)
    00084 {
    00085   ClearGRFConfigList(&grfconfig);
    00086   while (SlIterateArray() != -1) {
    00087     GRFConfig *c = new GRFConfig();
    00088     SlObject(c, _grfconfig_desc);
    00089     if (IsSavegameVersionBefore(101)) c->SetSuitablePalette();
    00090     AppendToGRFConfigList(&grfconfig, c);
    00091   }
    00092 }
    00093
    00094 static void Load_NGRF()
    00095 {
    00096   Load_NGRF_common(_grfconfig);
    00097
    00098   /* Append static NewGRF configuration */
    00099   AppendStaticGRFConfigs(&_grfconfig);
    00100 }
    00101
    00102 static void Check_NGRF()
    00103 {
    00104   Load_NGRF_common(_load_check_data.grfconfig);
    00105 }
    00106
    00107 extern const ChunkHandler _newgrf_chunk_handlers[] = {
    00108   { 'NGRF', Save_NGRF, Load_NGRF, NULL, Check_NGRF, CH_ARRAY | CH_LAST }
    00109 };