diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index fd4b64e..5d7976a 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1733,6 +1733,7 @@ bool ProcessOrders(Vehicle *v) if (((v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) || v->current_order.IsType(OT_GOTO_WAYPOINT)) && IsTileType(v->tile, MP_STATION) && v->current_order.GetDestination() == GetStationIndex(v->tile)) { + v->DeleteUnreachedAutoOrders(); /* We set the last visited station here because we do not want * the train to stop at this 'via' station if the next order * is a no-non-stop order; in that case not setting the last diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 8777ea1..63f820a 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1266,6 +1266,7 @@ void VehicleEnterDepot(Vehicle *v) if (t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) { /* Part of orders */ + v->DeleteUnreachedAutoOrders(); UpdateVehicleTimetable(v, true); v->IncrementOrderIndex(); } @@ -1737,6 +1738,17 @@ uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity) return capacity; } +/** + * Delete all automatic orders which were not reached. + */ +void Vehicle::DeleteUnreachedAutoOrders() { + const Order *order = this->GetOrder(this->cur_order_index); + while (order != NULL && order->IsType(OT_AUTOMATIC)) { + /* Delete order effectively deletes order, so get the next before deleting it. */ + order = order->next; + DeleteOrder(this, this->cur_order_index); + } +} void Vehicle::BeginLoading() { @@ -1744,13 +1756,7 @@ void Vehicle::BeginLoading() if (this->current_order.IsType(OT_GOTO_STATION) && this->current_order.GetDestination() == this->last_station_visited) { - /* Delete all automatic orders which were not reached */ - const Order *order = this->GetOrder(this->cur_order_index); - while (order != NULL && order->IsType(OT_AUTOMATIC)) { - /* Delete order effectively deletes order, so get the next before deleting it. */ - order = order->next; - DeleteOrder(this, this->cur_order_index); - } + this->DeleteUnreachedAutoOrders(); /* Now cur_order_index points to the destination station, and we can start loading */ this->current_order.MakeLoading(true); @@ -1765,12 +1771,12 @@ void Vehicle::BeginLoading() } else { /* We weren't scheduled to stop here. Insert an automatic order - * to show that we are stopping here. */ + * to show that we are stopping here, but only do that if the order + * list isn't empty. */ Order *in_list = this->GetOrder(this->cur_order_index); - if ((this->orders.list == NULL || this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID) && - ((in_list == NULL && this->cur_order_index == 0) || - (in_list != NULL && (!in_list->IsType(OT_AUTOMATIC) || - in_list->GetDestination() != this->last_station_visited)))) { + if (in_list != NULL && this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID && + (!in_list->IsType(OT_AUTOMATIC) || + in_list->GetDestination() != this->last_station_visited)) { Order *auto_order = new Order(); auto_order->MakeAutomatic(this->last_station_visited); InsertOrder(this, auto_order, this->cur_order_index); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 1e2ae6c..5ef9831 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -243,6 +243,8 @@ public: GroundVehicleCache *GetGroundVehicleCache(); const GroundVehicleCache *GetGroundVehicleCache() const; + void DeleteUnreachedAutoOrders(); + /** * Handle the loading of the vehicle; when not it skips through dummy * orders and does nothing in all other cases.