From a4052ca3480f7b032c2c8dab8dd13caca4d2cc12 Mon Sep 17 00:00:00 2001 From: Nicolas Chappe <74881848+nchappe@users.noreply.github.com> Date: Wed, 27 Jul 2022 18:44:12 +0200 Subject: [PATCH] Codechange: Add VehicleOrderSaver::Restore() --- src/train_cmd.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 2f0a743274..e2b9d375d2 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2449,6 +2449,7 @@ private: StationID old_last_station_visited; VehicleOrderID index; bool suppress_implicit_orders; + bool restored; public: VehicleOrderSaver(Train *_v) : @@ -2457,16 +2458,29 @@ public: old_dest_tile(_v->dest_tile), old_last_station_visited(_v->last_station_visited), index(_v->cur_real_order_index), - suppress_implicit_orders(HasBit(_v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS)) + suppress_implicit_orders(HasBit(_v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS)), + restored(false) { } - ~VehicleOrderSaver() + /** + * Restore the saved order to the vehicle. + */ + void Restore() { this->v->current_order = this->old_order; this->v->dest_tile = this->old_dest_tile; this->v->last_station_visited = this->old_last_station_visited; SB(this->v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS, 1, suppress_implicit_orders ? 1: 0); + this->restored = true; + } + + /** + * Restore the saved order to the vehicle, if Restore() has not already been called. + */ + ~VehicleOrderSaver() + { + if (!this->restored) this->Restore(); } /**