Initial minimal working tracerestrict implementation.
This is a port of the tracerestrict/routing restrictions feature from TTDPatch. At present this implements if tests (train length only), and pathfinder deny and penalty actions. This requires the use of YAPF. Note that restrictions are only evaluated within the YAPF lookahead distance.
This commit is contained in:
@@ -2988,6 +2988,8 @@ bool AfterLoadGame()
|
||||
ResetSignalHandlers();
|
||||
|
||||
AfterLoadLinkGraphs();
|
||||
|
||||
AfterLoadTraceRestrict();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -262,8 +262,9 @@
|
||||
* 192 26700
|
||||
* 193 26802
|
||||
* 194 26881 1.5.x
|
||||
* 2000 Trace restrict patch
|
||||
*/
|
||||
extern const uint16 SAVEGAME_VERSION = 194; ///< Current savegame version of OpenTTD.
|
||||
extern const uint16 SAVEGAME_VERSION = 2000; ///< Current savegame version of OpenTTD.
|
||||
|
||||
SavegameType _savegame_type; ///< type of savegame we are loading
|
||||
|
||||
@@ -447,6 +448,7 @@ extern const ChunkHandler _linkgraph_chunk_handlers[];
|
||||
extern const ChunkHandler _airport_chunk_handlers[];
|
||||
extern const ChunkHandler _object_chunk_handlers[];
|
||||
extern const ChunkHandler _persistent_storage_chunk_handlers[];
|
||||
extern const ChunkHandler _trace_restrict_chunk_handlers[];
|
||||
|
||||
/** Array of all chunks in a savegame, \c NULL terminated. */
|
||||
static const ChunkHandler * const _chunk_handlers[] = {
|
||||
@@ -483,6 +485,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
|
||||
_airport_chunk_handlers,
|
||||
_object_chunk_handlers,
|
||||
_persistent_storage_chunk_handlers,
|
||||
_trace_restrict_chunk_handlers,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ void AfterLoadLabelMaps();
|
||||
void AfterLoadStoryBook();
|
||||
void AfterLoadLinkGraphs();
|
||||
void AfterLoadCompanyStats();
|
||||
void AfterLoadTraceRestrict();
|
||||
void UpdateHousesAndTowns();
|
||||
|
||||
void UpdateOldAircraft();
|
||||
|
||||
92
src/saveload/tracerestrict_sl.cpp
Normal file
92
src/saveload/tracerestrict_sl.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/* $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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file tracerestrict_sl.cpp Code handling saving and loading of trace restrict programs */
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../tracerestrict.h"
|
||||
#include "saveload.h"
|
||||
#include <vector>
|
||||
#include "saveload.h"
|
||||
|
||||
static const SaveLoad _trace_restrict_mapping_desc[] = {
|
||||
SLE_VAR(TraceRestrictMappingItem, program_id, SLE_UINT32),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static void Load_TRRM()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
TraceRestrictMappingItem &item = _tracerestrictprogram_mapping[index];
|
||||
SlObject(&item, _trace_restrict_mapping_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_TRRM()
|
||||
{
|
||||
for (TraceRestrictMapping::iterator iter = _tracerestrictprogram_mapping.begin();
|
||||
iter != _tracerestrictprogram_mapping.end(); ++iter) {
|
||||
SlSetArrayIndex(iter->first);
|
||||
SlObject(&(iter->second), _trace_restrict_mapping_desc);
|
||||
}
|
||||
}
|
||||
|
||||
struct TraceRestrictProgramStub {
|
||||
uint32 length;
|
||||
};
|
||||
|
||||
static const SaveLoad _trace_restrict_program_stub_desc[] = {
|
||||
SLE_VAR(TraceRestrictProgramStub, length, SLE_UINT32),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static void Load_TRRP()
|
||||
{
|
||||
int index;
|
||||
TraceRestrictProgramStub stub;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
TraceRestrictProgram *prog = new (index) TraceRestrictProgram();
|
||||
SlObject(&stub, _trace_restrict_program_stub_desc);
|
||||
prog->items.resize(stub.length);
|
||||
SlArray(&(prog->items[0]), stub.length, SLE_UINT32);
|
||||
assert(prog->Validate().Succeeded());
|
||||
}
|
||||
}
|
||||
|
||||
static void RealSave_TRRP(TraceRestrictProgram *prog)
|
||||
{
|
||||
TraceRestrictProgramStub stub;
|
||||
stub.length = prog->items.size();
|
||||
SlObject(&stub, _trace_restrict_program_stub_desc);
|
||||
SlArray(&(prog->items[0]), stub.length, SLE_UINT32);
|
||||
}
|
||||
|
||||
static void Save_TRRP()
|
||||
{
|
||||
TraceRestrictProgram *prog;
|
||||
|
||||
FOR_ALL_TRACE_RESTRICT_PROGRAMS(prog) {
|
||||
SlSetArrayIndex(prog->index);
|
||||
SlAutolength((AutolengthProc*) RealSave_TRRP, prog);
|
||||
}
|
||||
}
|
||||
|
||||
void AfterLoadTraceRestrict()
|
||||
{
|
||||
for (TraceRestrictMapping::iterator iter = _tracerestrictprogram_mapping.begin();
|
||||
iter != _tracerestrictprogram_mapping.end(); ++iter) {
|
||||
_tracerestrictprogram_pool.Get(iter->second.program_id)->IncrementRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _trace_restrict_chunk_handlers[] = {
|
||||
{ 'TRRM', Save_TRRM, Load_TRRM, NULL, NULL, CH_SPARSE_ARRAY},
|
||||
{ 'TRRP', Save_TRRP, Load_TRRP, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
Reference in New Issue
Block a user