autoreplace_sl.cpp

Go to the documentation of this file.
00001 /* $Id: autoreplace_sl.cpp 24136 2012-04-17 19:44:02Z michi_cc $ */
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_CONDVAR(EngineRenew, replace_when_old, SLE_BOOL, 175, SL_MAX_VERSION),
00024   SLE_END()
00025 };
00026 
00027 static void Save_ERNW()
00028 {
00029   EngineRenew *er;
00030 
00031   FOR_ALL_ENGINE_RENEWS(er) {
00032     SlSetArrayIndex(er->index);
00033     SlObject(er, _engine_renew_desc);
00034   }
00035 }
00036 
00037 static void Load_ERNW()
00038 {
00039   int index;
00040 
00041   while ((index = SlIterateArray()) != -1) {
00042     EngineRenew *er = new (index) EngineRenew();
00043     SlObject(er, _engine_renew_desc);
00044 
00045     /* Advanced vehicle lists, ungrouped vehicles got added */
00046     if (IsSavegameVersionBefore(60)) {
00047       er->group_id = ALL_GROUP;
00048     } else if (IsSavegameVersionBefore(71)) {
00049       if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
00050     }
00051   }
00052 }
00053 
00054 static void Ptrs_ERNW()
00055 {
00056   EngineRenew *er;
00057 
00058   FOR_ALL_ENGINE_RENEWS(er) {
00059     SlObject(er, _engine_renew_desc);
00060   }
00061 }
00062 
00063 extern const ChunkHandler _autoreplace_chunk_handlers[] = {
00064   { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, NULL, CH_ARRAY | CH_LAST},
00065 };