Feature: Region-based pathfinder for ships (#10543)
This commit is contained in:
@@ -44,4 +44,5 @@ add_files(
|
||||
town_sl.cpp
|
||||
vehicle_sl.cpp
|
||||
waypoint_sl.cpp
|
||||
water_regions_sl.cpp
|
||||
)
|
||||
|
@@ -61,6 +61,7 @@
|
||||
#include "../timer/timer.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../timer/timer_game_tick.h"
|
||||
#include "../pathfinder/water_regions.h"
|
||||
|
||||
#include "saveload_internal.h"
|
||||
|
||||
@@ -3296,6 +3297,8 @@ bool AfterLoadGame()
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_WATER_REGIONS)) InitializeWaterRegions();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -249,6 +249,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
|
||||
extern const ChunkHandlerTable _airport_chunk_handlers;
|
||||
extern const ChunkHandlerTable _object_chunk_handlers;
|
||||
extern const ChunkHandlerTable _persistent_storage_chunk_handlers;
|
||||
extern const ChunkHandlerTable _water_region_chunk_handlers;
|
||||
|
||||
/** List of all chunks in a savegame. */
|
||||
static const ChunkHandlerTable _chunk_handler_tables[] = {
|
||||
@@ -286,6 +287,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
|
||||
_airport_chunk_handlers,
|
||||
_object_chunk_handlers,
|
||||
_persistent_storage_chunk_handlers,
|
||||
_water_region_chunk_handlers,
|
||||
};
|
||||
|
||||
static std::vector<ChunkHandlerRef> _chunk_handlers;
|
||||
|
@@ -366,6 +366,7 @@ enum SaveLoadVersion : uint16_t {
|
||||
SLV_TIMETABLE_START_TICKS, ///< 321 PR#11468 Convert timetable start from a date to ticks.
|
||||
SLV_TIMETABLE_START_TICKS_FIX, ///< 322 PR#11557 Fix for missing convert timetable start from a date to ticks.
|
||||
SLV_TIMETABLE_TICKS_TYPE, ///< 323 PR#11435 Convert timetable current order time to ticks.
|
||||
SLV_WATER_REGIONS, ///< 324 PR#10543 Water Regions for ship pathfinder.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
|
54
src/saveload/water_regions_sl.cpp
Normal file
54
src/saveload/water_regions_sl.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 water_regions_sl.cpp Handles saving and loading of water region data */
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "saveload.h"
|
||||
#include "pathfinder/water_regions.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const SaveLoad _water_region_desc[] = {
|
||||
SLE_VAR(WaterRegionSaveLoadInfo, initialized, SLE_BOOL),
|
||||
};
|
||||
|
||||
struct WRGNChunkHandler : ChunkHandler {
|
||||
WRGNChunkHandler() : ChunkHandler('WRGN', CH_TABLE) {}
|
||||
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(_water_region_desc);
|
||||
|
||||
int index = 0;
|
||||
for (WaterRegionSaveLoadInfo ®ion : GetWaterRegionSaveLoadInfo()) {
|
||||
SlSetArrayIndex(index++);
|
||||
SlObject(®ion, _water_region_desc);
|
||||
}
|
||||
}
|
||||
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlTableHeader(_water_region_desc);
|
||||
|
||||
int index;
|
||||
|
||||
std::vector<WaterRegionSaveLoadInfo> loaded_info;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
WaterRegionSaveLoadInfo region_info;
|
||||
SlObject(®ion_info, slt);
|
||||
loaded_info.push_back(std::move(region_info));
|
||||
}
|
||||
|
||||
LoadWaterRegions(loaded_info);
|
||||
}
|
||||
};
|
||||
|
||||
static const WRGNChunkHandler WRGN;
|
||||
static const ChunkHandlerRef water_region_chunk_handlers[] = { WRGN };
|
||||
extern const ChunkHandlerTable _water_region_chunk_handlers(water_region_chunk_handlers);
|
Reference in New Issue
Block a user