diff --git a/source.list b/source.list index 125198c23c..58f5a9fc6e 100644 --- a/source.list +++ b/source.list @@ -671,6 +671,7 @@ saveload/strings_sl.cpp saveload/story_sl.cpp saveload/subsidy_sl.cpp saveload/town_sl.cpp +saveload/tunnel_sl.cpp saveload/vehicle_sl.cpp saveload/waypoint_sl.cpp saveload/signal_sl.cpp diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 47b175d1e2..76f3349ea5 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2030,23 +2030,26 @@ bool AfterLoadGame() } /* Tunnel pool has to be initiated before reservations. */ - for (TileIndex t = 0; t < map_size; t++) { - if (IsTunnelTile(t)) { - DiagDirection dir = GetTunnelBridgeDirection(t); - if (dir == DIAGDIR_SE || dir == DIAGDIR_SW) { - TileIndex start_tile = t; - TileIndex end_tile = GetOtherTunnelBridgeEndOLd(start_tile); + if (IsSavegameVersionBefore(196)) { + for (TileIndex t = 0; t < map_size; t++) { + if (IsTunnelTile(t)) { + DiagDirection dir = GetTunnelBridgeDirection(t); + if (dir == DIAGDIR_SE || dir == DIAGDIR_SW) { + TileIndex start_tile = t; + TileIndex end_tile = GetOtherTunnelBridgeEndOLd(start_tile); - if (!Tunnel::CanAllocateItem()) return false; + if (!Tunnel::CanAllocateItem()) return false; - Tunnel *t = new Tunnel(start_tile); - t->tile_s = end_tile; + Tunnel *t = new Tunnel(start_tile); + t->tile_s = end_tile; + t->is_chunnel = 0; - DEBUG(misc, 0, "Tun start %#x, index=%#x", t->tile_n, t->index); - DEBUG(misc, 0, "Tun end %#x, index=%#x", t->tile_s, t->index); + DEBUG(misc, 0, "Tun start %#x, index=%#x", t->tile_n, t->index); + DEBUG(misc, 0, "Tun end %#x, index=%#x", t->tile_s, t->index); - _m[start_tile].m2 = t->index; - _m[end_tile].m2 = t->index; + _m[start_tile].m2 = t->index; + _m[end_tile].m2 = t->index; + } } } } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index cf82659e17..3376d074b8 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -270,7 +270,7 @@ * 194 26881 1.5.x, 1.6.0 * 195 27572 1.6.x */ -extern const uint16 SAVEGAME_VERSION = 195; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 196; ///< Current savegame version of OpenTTD. const uint16 SAVEGAME_VERSION_EXT = 0x8000; ///< Savegame extension indicator mask SavegameType _savegame_type; ///< type of savegame we are loading @@ -465,6 +465,7 @@ extern const ChunkHandler _plan_chunk_handlers[]; extern const ChunkHandler _template_replacement_chunk_handlers[]; extern const ChunkHandler _template_vehicle_chunk_handlers[]; extern const ChunkHandler _bridge_signal_chunk_handlers[]; +extern const ChunkHandler _tunnel_chunk_handlers[]; /** Array of all chunks in a savegame, \c NULL terminated. */ static const ChunkHandler * const _chunk_handlers[] = { @@ -508,6 +509,7 @@ static const ChunkHandler * const _chunk_handlers[] = { _template_replacement_chunk_handlers, _template_vehicle_chunk_handlers, _bridge_signal_chunk_handlers, + _tunnel_chunk_handlers, NULL, }; diff --git a/src/saveload/tunnel_sl.cpp b/src/saveload/tunnel_sl.cpp new file mode 100644 index 0000000000..f477ef6e7b --- /dev/null +++ b/src/saveload/tunnel_sl.cpp @@ -0,0 +1,50 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * 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. + * 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. + * 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 . + */ + +/** @file tunnel_sl.cpp Code handling saving and loading of tunnels */ + +#include "../stdafx.h" +#include "../tunnel_base.h" + +#include "saveload.h" + +#include "../safeguards.h" + + +static const SaveLoad _tunnel_desc[] = { + SLE_CONDVAR(Tunnel, tile_n, SLE_UINT32, 196, SL_MAX_VERSION), + SLE_CONDVAR(Tunnel, tile_s, SLE_UINT32, 196, SL_MAX_VERSION), + SLE_CONDVAR(Tunnel, is_chunnel, SLE_BOOL, 196, SL_MAX_VERSION), + SLE_END() +}; + +static void Save_TUNN() +{ + Tunnel *tunnel; + + FOR_ALL_TUNNELS(tunnel) { + SlSetArrayIndex(tunnel->index); + SlObject(tunnel, _tunnel_desc); + } +} + +static void Load_TUNN() +{ + int index; + + while ((index = SlIterateArray()) != -1) { + Tunnel *tunnel = new (index) Tunnel(); + SlObject(tunnel, _tunnel_desc); + } +} + + +extern const ChunkHandler _tunnel_chunk_handlers[] = { + { 'TUNN', Save_TUNN, Load_TUNN, NULL, NULL, CH_ARRAY | CH_LAST}, +};