diff --git a/src/order_base.h b/src/order_base.h index 4023b2bb4f..338176bfed 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -106,12 +106,12 @@ private: friend void Load_VEHS(); ///< Loading of ancient vehicles. friend NamedSaveLoadTable GetOrderDescription(); ///< Saving and loading of orders. friend struct OrderExtraDataStructHandler; ///< Saving and loading of orders. + friend struct VehicleOrderExtraDataStructHandler; ///< Saving and loading of orders. friend upstream_sl::SaveLoadTable upstream_sl::GetOrderDescription(); ///< Saving and loading of orders. friend upstream_sl::SlVehicleCommon; friend upstream_sl::SlVehicleDisaster; friend void Load_ORDX(); ///< Saving and loading of orders. friend void Load_VEOX(); ///< Saving and loading of orders. - friend void Save_VEOX(); ///< Saving and loading of orders. uint16_t flags; ///< Load/unload types, depot order/action types. DestinationID dest; ///< The destination of the order. diff --git a/src/sl/extended_ver_sl.cpp b/src/sl/extended_ver_sl.cpp index be6afb8593..1343b0422f 100644 --- a/src/sl/extended_ver_sl.cpp +++ b/src/sl/extended_ver_sl.cpp @@ -112,7 +112,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 6, 6, "linkgraph_day_scale", nullptr, nullptr, nullptr }, { XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 10, 10, "template_replacement", nullptr, nullptr, "TRPL,TMPL" }, { XSLFI_MORE_RAIL_TYPES, XSCF_NULL, 0, 1, "more_rail_types", nullptr, nullptr, nullptr }, - { XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 3, 3, "cargo_type_orders", nullptr, nullptr, "ORDX,VEOX" }, + { XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 4, 4, "cargo_type_orders", nullptr, nullptr, nullptr }, { XSLFI_EXTENDED_GAMELOG, XSCF_NULL, 2, 2, "extended_gamelog", nullptr, nullptr, nullptr }, { 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 }, @@ -120,7 +120,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 8, 8, "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" }, + { XSLFI_TIMETABLE_EXTRA, XSCF_NULL, 8, 8, "timetable_extra", nullptr, nullptr, nullptr }, { XSLFI_TRAIN_FLAGS_EXTRA, XSCF_NULL, 1, 1, "train_flags_extra", nullptr, nullptr, nullptr }, { XSLFI_VEHICLE_FLAGS_EXTRA, XSCF_NULL, 1, 1, "veh_flags_extra", nullptr, nullptr, nullptr }, { XSLFI_TRAIN_THROUGH_LOAD, XSCF_NULL, 2, 2, "train_through_load", nullptr, nullptr, nullptr }, diff --git a/src/sl/vehicle_sl.cpp b/src/sl/vehicle_sl.cpp index 84be92202b..ed8b52d8a9 100644 --- a/src/sl/vehicle_sl.cpp +++ b/src/sl/vehicle_sl.cpp @@ -36,6 +36,8 @@ extern btree::btree_multimap _pending_speed_restriction_change_map; +extern SaveLoadStructHandlerFactory MakeOrderExtraDataStructHandler(); + /** * Link front and rear multiheaded engines to each other * This is done when loading a savegame @@ -772,6 +774,27 @@ struct VehicleTypeStructHandler final : public TypedSaveLoadStructHandler { + NamedSaveLoadTable GetDescription() const override + { + extern NamedSaveLoadTable GetOrderExtraInfoDescription(); + return GetOrderExtraInfoDescription(); + } + + void Save(Vehicle *v) const override + { + if (!v->current_order.extra) return; + + SlObjectSaveFiltered(v->current_order.extra.get(), this->GetLoadDescription()); + } + + void Load(Vehicle *v) const override + { + v->current_order.AllocExtraInfo(); + SlObjectLoadFiltered(v->current_order.extra.get(), this->GetLoadDescription()); + } +}; + const NamedSaveLoadTable GetVehicleUnbunchStateDescription() { static const NamedSaveLoad _vehicle_unbunch_state_desc[] = { @@ -1014,6 +1037,9 @@ NamedSaveLoadTable GetVehicleDescription(VehicleType vt) NSL("current_order.travel_time",SLE_CONDVAR_X(Vehicle, current_order.travel_time, SLE_FILE_U16 | SLE_VAR_U32, SLV_67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 0, 5))), NSL("current_order.travel_time",SLE_CONDVAR_X(Vehicle, current_order.travel_time, SLE_UINT32, SLV_67, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA, 6))), NSL("current_order.max_speed", SLE_CONDVAR(Vehicle, current_order.max_speed, SLE_UINT16, SLV_174, SL_MAX_VERSION)), + + NSLT_STRUCT("current_order.extra"), + NSL("timetable_start", SLE_CONDVAR_X(Vehicle, timetable_start, SLE_FILE_I32 | SLE_VAR_I64, SLV_129, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLES_START_TICKS, 0, 2))), NSL("timetable_start", SLE_CONDVAR_X(Vehicle, timetable_start, SLE_INT64, SLV_129, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLES_START_TICKS, 3))), NSL("", SLEG_CONDVAR_X(_old_timetable_start_subticks, SLE_UINT16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLES_START_TICKS, 2, 2))), @@ -1418,23 +1444,9 @@ static void Ptrs_VEHS() } } -NamedSaveLoadTable GetOrderExtraInfoDescription(); - -void Save_VEOX() -{ - std::vector slt = SlFilterNamedSaveLoadTable(GetOrderExtraInfoDescription()); - - /* save extended order info for vehicle current order */ - for (Vehicle *v : Vehicle::Iterate()) { - if (v->current_order.extra) { - SlSetArrayIndex(v->index); - SlObject(v->current_order.extra.get(), slt); - } - } -} - void Load_VEOX() { + extern NamedSaveLoadTable GetOrderExtraInfoDescription(); std::vector slt = SlFilterNamedSaveLoadTable(GetOrderExtraInfoDescription()); /* load extended order info for vehicle current order */ @@ -1793,7 +1805,7 @@ void Load_VUBS() static const ChunkHandler veh_chunk_handlers[] = { { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_TABLE }, - { 'VEOX', Save_VEOX, Load_VEOX, nullptr, nullptr, CH_SPARSE_ARRAY }, + { 'VEOX', nullptr, Load_VEOX, nullptr, nullptr, CH_READONLY }, { 'VESR', Save_VESR, Load_VESR, nullptr, nullptr, CH_SPARSE_ARRAY }, { 'VENC', Save_VENC, Load_VENC, nullptr, nullptr, CH_RIFF, Special_VENC }, { 'VLKA', nullptr, Load_VLKA, nullptr, nullptr, CH_READONLY },