diff options
author | frosch <frosch@openttd.org> | 2011-01-31 20:44:15 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-01-31 20:44:15 +0000 |
commit | a97d52a29a990132a8a5e4dd60304483617cec50 (patch) | |
tree | 0d8d42d633feabb438f812cedf0534a3c665074e /src/vehicle_base.h | |
parent | 67a5cd0b185158ca4926c8cb45f1735a1001e00b (diff) | |
download | openttd-a97d52a29a990132a8a5e4dd60304483617cec50.tar.xz |
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
-Fix [FS#4440]: Automatic orders behave now stable wrt. service orders and are not added or removed depending on the need of servicing.
-Fix: Various other issues with automatic orders, e.g. vehicles getting stuck with "no orders" when there are automatic orders at the end of the order list.
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r-- | src/vehicle_base.h | 84 |
1 files changed, 76 insertions, 8 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 623f534fb..a838edcbf 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -222,7 +222,8 @@ public: byte vehstatus; ///< Status Order current_order; ///< The current order (+ status, like: loading) - VehicleOrderID cur_order_index; ///< The index to the current order + VehicleOrderID cur_real_order_index;///< The index to the current real (non-automatic) order + VehicleOrderID cur_auto_order_index;///< The index to the current automatic order union { OrderList *list; ///< Pointer to the order list for this vehicle @@ -549,7 +550,8 @@ public: { this->unitnumber = src->unitnumber; - this->cur_order_index = src->cur_order_index; + this->cur_real_order_index = src->cur_real_order_index; + this->cur_auto_order_index = src->cur_auto_order_index; this->current_order = src->current_order; this->dest_tile = src->dest_tile; @@ -599,18 +601,86 @@ public: void UpdateVisualEffect(bool allow_power_change = true); void ShowVisualEffect() const; +private: /** - * Increments cur_order_index, keeps care of the wrap-around and invalidates the GUI. + * Advance cur_real_order_index to the next real order. + * cur_auto_order_index is not touched. + */ + void SkipToNextRealOrderIndex() + { + if (this->GetNumManualOrders() > 0) { + /* Advance to next real order */ + do { + this->cur_real_order_index++; + if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0; + } while (this->GetOrder(this->cur_real_order_index)->IsType(OT_AUTOMATIC)); + } else { + this->cur_real_order_index = 0; + } + } + +public: + /** + * Increments cur_auto_order_index, keeps care of the wrap-around and invalidates the GUI. + * cur_real_order_index is incremented as well, if needed. * Note: current_order is not invalidated. */ - void IncrementOrderIndex() + void IncrementAutoOrderIndex() { - this->cur_order_index++; - if (this->cur_order_index >= this->GetNumOrders()) this->cur_order_index = 0; + if (this->cur_auto_order_index == this->cur_real_order_index) { + /* Increment real order index as well */ + this->SkipToNextRealOrderIndex(); + } + + assert(this->cur_real_order_index == 0 || this->cur_real_order_index < this->GetNumOrders()); + + /* Advance to next automatic order */ + do { + this->cur_auto_order_index++; + if (this->cur_auto_order_index >= this->GetNumOrders()) this->cur_auto_order_index = 0; + } while (this->cur_auto_order_index != this->cur_real_order_index && !this->GetOrder(this->cur_auto_order_index)->IsType(OT_AUTOMATIC)); + InvalidateVehicleOrder(this, 0); } /** + * Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates the GUI. + * cur_auto_order_index is incremented as well, if it was equal to cur_real_order_index, i.e. cur_real_order_index is skipped + * but not any automatic orders. + * Note: current_order is not invalidated. + */ + void IncrementRealOrderIndex() + { + if (this->cur_auto_order_index == this->cur_real_order_index) { + /* Increment both real and auto order */ + this->IncrementAutoOrderIndex(); + } else { + /* Increment real order only */ + this->SkipToNextRealOrderIndex(); + InvalidateVehicleOrder(this, 0); + } + } + + /** + * Skip automatic orders until cur_real_order_index is a non-automatic order. + */ + void UpdateRealOrderIndex() + { + /* Make sure the index is valid */ + if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0; + + if (this->GetNumManualOrders() > 0) { + /* Advance to next real order */ + while (this->GetOrder(this->cur_real_order_index)->IsType(OT_AUTOMATIC)) { + this->cur_real_order_index++; + if (this->cur_real_order_index >= this->GetNumOrders()) this->cur_real_order_index = 0; + } + } else { + this->cur_real_order_index = 0; + } + } + + /** * Returns order 'index' of a vehicle or NULL when it doesn't exists * @param index the order to fetch * @return the found (or not) order @@ -620,8 +690,6 @@ public: return (this->orders.list == NULL) ? NULL : this->orders.list->GetOrderAt(index); } - Order *GetNextManualOrder(int index) const; - /** * Returns the last order of a vehicle, or NULL if it doesn't exists * @return last order of a vehicle, if available |