# autoreplace_sl.cpp

Go to the documentation of this file.

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