Scheduled dispatch: Add per dispatch slot flags field

Add flag for slot re-use
This commit is contained in:
Jonathan G Rennison
2024-01-28 01:48:54 +00:00
parent dee611f5f3
commit 6c329871f1
11 changed files with 260 additions and 49 deletions

View File

@@ -117,7 +117,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_STATION_CATCHMENT_INC, XSCF_NULL, 1, 1, "station_catchment_inc", nullptr, nullptr, nullptr },
{ XSLFI_CUSTOM_BRIDGE_HEADS, XSCF_NULL, 4, 4, "custom_bridge_heads", nullptr, nullptr, nullptr },
{ XSLFI_CHUNNEL, XSCF_NULL, 2, 2, "chunnel", nullptr, nullptr, "TUNN" },
{ XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 6, 6, "scheduled_dispatch", nullptr, nullptr, nullptr },
{ XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 7, 7, "scheduled_dispatch", nullptr, nullptr, nullptr },
{ XSLFI_MORE_TOWN_GROWTH_RATES, XSCF_NULL, 1, 1, "more_town_growth_rates", nullptr, nullptr, nullptr },
{ XSLFI_MULTIPLE_DOCKS, XSCF_NULL, 2, 2, "multiple_docks", nullptr, nullptr, nullptr },
{ XSLFI_TIMETABLE_EXTRA, XSCF_NULL, 7, 7, "timetable_extra", nullptr, nullptr, "ORDX" },

View File

@@ -22,6 +22,7 @@ std::vector<OrderList *> _jokerpp_non_auto_separation;
static uint16_t _old_scheduled_dispatch_start_full_date_fract;
btree::btree_map<DispatchSchedule *, uint16_t> _old_scheduled_dispatch_start_full_date_fract_map;
static std::vector<uint32_t> _old_scheduled_dispatch_slots;
/**
* Converts this order from an old savegame's version;
@@ -264,7 +265,7 @@ static void Ptrs_ORDR()
SaveLoadTable GetDispatchScheduleDescription()
{
static const SaveLoad _dispatch_scheduled_info_desc[] = {
SLE_VARVEC(DispatchSchedule, scheduled_dispatch, SLE_UINT32),
SLEG_CONDVARVEC_X(_old_scheduled_dispatch_slots, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SCHEDULED_DISPATCH, 1, 6)),
SLE_VAR(DispatchSchedule, scheduled_dispatch_duration, SLE_UINT32),
SLE_CONDVAR_X(DispatchSchedule, scheduled_dispatch_start_tick, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SCHEDULED_DISPATCH, 1, 4)),
SLEG_CONDVAR_X(_old_scheduled_dispatch_start_full_date_fract, SLE_UINT16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SCHEDULED_DISPATCH, 1, 4)),
@@ -278,6 +279,16 @@ SaveLoadTable GetDispatchScheduleDescription()
return _dispatch_scheduled_info_desc;
}
SaveLoadTable GetDispatchSlotDescription()
{
static const SaveLoad _dispatch_slot_info_desc[] = {
SLE_VAR(DispatchSlot, offset, SLE_UINT32),
SLE_VAR(DispatchSlot, flags, SLE_UINT16),
};
return _dispatch_slot_info_desc;
}
SaveLoadTable GetOrderListDescription()
{
static const SaveLoad _orderlist_desc[] = {
@@ -291,11 +302,13 @@ SaveLoadTable GetOrderListDescription()
static std::vector<SaveLoad> _filtered_ordl_desc;
static std::vector<SaveLoad> _filtered_ordl_sd_desc;
static std::vector<SaveLoad> _filtered_ordl_slot_desc;
static void SetupDescs_ORDL()
{
_filtered_ordl_desc = SlFilterObject(GetOrderListDescription());
_filtered_ordl_sd_desc = SlFilterObject(GetDispatchScheduleDescription());
_filtered_ordl_slot_desc = SlFilterObject(GetDispatchSlotDescription());
}
static void Save_ORDL()
@@ -309,6 +322,11 @@ static void Save_ORDL()
SlWriteUint32(list->GetScheduledDispatchScheduleCount());
for (DispatchSchedule &ds : list->GetScheduledDispatchScheduleSet()) {
SlObjectSaveFiltered(&ds, _filtered_ordl_sd_desc);
SlWriteUint32((uint32_t)ds.GetScheduledDispatchMutable().size());
for (DispatchSlot &slot : ds.GetScheduledDispatchMutable()) {
SlObjectSaveFiltered(&slot, _filtered_ordl_slot_desc);
}
}
}, list);
}
@@ -344,9 +362,23 @@ static void Load_ORDL()
if (SlXvIsFeaturePresent(XSLFI_SCHEDULED_DISPATCH, 1, 4) && _old_scheduled_dispatch_start_full_date_fract != 0) {
_old_scheduled_dispatch_start_full_date_fract_map[&ds] = _old_scheduled_dispatch_start_full_date_fract;
}
if (SlXvIsFeaturePresent(XSLFI_SCHEDULED_DISPATCH, 1, 6)) {
ds.GetScheduledDispatchMutable().reserve(_old_scheduled_dispatch_slots.size());
for (uint32_t slot : _old_scheduled_dispatch_slots) {
ds.GetScheduledDispatchMutable().push_back({ slot, 0 });
}
} else {
ds.GetScheduledDispatchMutable().resize(SlReadUint32());
for (DispatchSlot &slot : ds.GetScheduledDispatchMutable()) {
SlObjectLoadFiltered(&slot, _filtered_ordl_slot_desc);
}
}
}
}
}
_old_scheduled_dispatch_slots.clear();
}
void Ptrs_ORDL()