Store signal style GRF to local map in savegame

Update existing signal style IDs as necessary
This commit is contained in:
Jonathan G Rennison
2022-06-25 14:33:47 +01:00
parent a73bc141a1
commit 04da11b668
9 changed files with 173 additions and 25 deletions

View File

@@ -28,6 +28,7 @@ add_files(
misc_sl.cpp
newgrf_sl.cpp
newgrf_sl.h
newsignals_sl.cpp
object_sl.cpp
oldloader.cpp
oldloader.h

View File

@@ -173,7 +173,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_RV_ORDER_EXTRA_FLAGS, XSCF_IGNORABLE_UNKNOWN, 1, 1, "rv_order_extra_flags", nullptr, nullptr, nullptr },
{ XSLFI_GRF_ROADSTOPS, XSCF_NULL, 1, 1, "grf_road_stops", nullptr, nullptr, nullptr },
{ XSLFI_INDUSTRY_ANIM_MASK, XSCF_IGNORABLE_ALL, 1, 1, "industry_anim_mask", nullptr, nullptr, nullptr },
{ XSLFI_NEW_SIGNAL_STYLES, XSCF_NULL, 1, 1, "new_signal_styles", nullptr, nullptr, "XBST" },
{ XSLFI_NEW_SIGNAL_STYLES, XSCF_NULL, 2, 2, "new_signal_styles", nullptr, nullptr, "XBST,NSID" },
{ XSLFI_SCRIPT_INT64, XSCF_NULL, 1, 1, "script_int64", nullptr, nullptr, nullptr },
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker
};

View File

@@ -0,0 +1,42 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
/** @file newsignals_sl.cpp Code handling saving and loading of new signals */
#include "../stdafx.h"
#include "../newgrf_newsignals.h"
#include "saveload.h"
#include "../safeguards.h"
static void Save_NSID()
{
SlSetLength(4 + (lengthof(_new_signal_style_mapping) * 5));
SlWriteUint32(lengthof(_new_signal_style_mapping));
for (const NewSignalStyleMapping &mapping : _new_signal_style_mapping) {
SlWriteUint32(mapping.grfid);
SlWriteByte(mapping.grf_local_id);
}
}
static void Load_NSID()
{
uint count = SlReadUint32();
for (uint i = 0; i < count; i++) {
NewSignalStyleMapping mapping;
mapping.grfid = SlReadUint32();
mapping.grf_local_id = SlReadByte();
if (i < lengthof(_new_signal_style_mapping)) _new_signal_style_mapping[i] = mapping;
}
}
static const ChunkHandler new_signal_chunk_handlers[] = {
{ 'NSID', Save_NSID, Load_NSID, nullptr, nullptr, CH_RIFF },
};
extern const ChunkHandlerTable _new_signal_chunk_handlers(new_signal_chunk_handlers);

View File

@@ -300,6 +300,7 @@ static const std::vector<ChunkHandler> &ChunkHandlers()
extern const ChunkHandlerTable _bridge_signal_chunk_handlers;
extern const ChunkHandlerTable _tunnel_chunk_handlers;
extern const ChunkHandlerTable _train_speed_adaptation_chunk_handlers;
extern const ChunkHandlerTable _new_signal_chunk_handlers;
extern const ChunkHandlerTable _debug_chunk_handlers;
/** List of all chunks in a savegame. */
@@ -346,6 +347,7 @@ static const std::vector<ChunkHandler> &ChunkHandlers()
_bridge_signal_chunk_handlers,
_tunnel_chunk_handlers,
_train_speed_adaptation_chunk_handlers,
_new_signal_chunk_handlers,
_debug_chunk_handlers,
};