# autoreplace_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: autoreplace_sl.cpp 18809 2010-01-15 16:41:15Z 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 "../autoreplace_base.h"
    00014
    00015 #include "saveload.h"
    00016
    00017 static const SaveLoad _engine_renew_desc[] = {
    00018       SLE_VAR(EngineRenew, from,     SLE_UINT16),
    00019       SLE_VAR(EngineRenew, to,       SLE_UINT16),
    00020
    00021       SLE_REF(EngineRenew, next,     REF_ENGINE_RENEWS),
    00022   SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),
    00023   SLE_END()
    00024 };
    00025
    00026 static void Save_ERNW()
    00027 {
    00028   EngineRenew *er;
    00029
    00030   FOR_ALL_ENGINE_RENEWS(er) {
    00031     SlSetArrayIndex(er->index);
    00032     SlObject(er, _engine_renew_desc);
    00033   }
    00034 }
    00035
    00036 static void Load_ERNW()
    00037 {
    00038   int index;
    00039
    00040   while ((index = SlIterateArray()) != -1) {
    00041     EngineRenew *er = new (index) EngineRenew();
    00042     SlObject(er, _engine_renew_desc);
    00043
    00044     /* Advanced vehicle lists, ungrouped vehicles got added */
    00045     if (CheckSavegameVersion(60)) {
    00046       er->group_id = ALL_GROUP;
    00047     } else if (CheckSavegameVersion(71)) {
    00048       if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
    00049     }
    00050   }
    00051 }
    00052
    00053 static void Ptrs_ERNW()
    00054 {
    00055   EngineRenew *er;
    00056
    00057   FOR_ALL_ENGINE_RENEWS(er) {
    00058     SlObject(er, _engine_renew_desc);
    00059   }
    00060 }
    00061
    00062 extern const ChunkHandler _autoreplace_chunk_handlers[] = {
    00063   { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, CH_ARRAY | CH_LAST},
    00064 };