# newgrf_sl.cpp

Go to the documentation of this file.

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