Changeset - r26469:d443093474bb
[Not reviewed]
master
0 1 0
Nicolas Chappe - 23 months ago 2022-07-27 16:44:12
74881848+nchappe@users.noreply.github.com
Codechange: Add VehicleOrderSaver::Restore()
1 file changed with 16 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -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();
 
	}
 

	
 
	/**
0 comments (0 inline, 0 general)