From 64f04c3a74be3769a3e0bbf2e1c68bd27d6579eb Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 26 Dec 2010 09:03:19 +0000 Subject: (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen --- src/vehicle.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/vehicle.cpp') diff --git a/src/vehicle.cpp b/src/vehicle.cpp index bc5469062..9dc25a2dd 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1231,7 +1231,7 @@ void VehicleEnterDepot(Vehicle *v) if (v->current_order.IsType(OT_GOTO_DEPOT)) { SetWindowDirty(WC_VEHICLE_VIEW, v->index); - const Order *real_order = v->GetOrder(v->cur_order_index); + const Order *real_order = v->GetNextManualOrder(v->cur_order_index); Order t = v->current_order; v->current_order.MakeDummy(); @@ -1747,6 +1747,12 @@ void Vehicle::BeginLoading() current_order.MakeLoading(true); UpdateVehicleTimetable(this, true); + for (Order *order = this->GetOrder(this->cur_order_index); + order != NULL && order->IsType(OT_AUTOMATIC); + order = order->next) { + DeleteOrder(this, this->cur_order_index); + } + /* Furthermore add the Non Stop flag to mark that this station * is the actual destination of the vehicle, which is (for example) * necessary to be known for HandleTrainLoading to determine @@ -1755,6 +1761,18 @@ void Vehicle::BeginLoading() this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION); } else { + /* We weren't scheduled to stop here. Insert an automatic order + * to show that we are stopping here. */ + Order *in_list = this->GetOrder(this->cur_order_index); + if (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)))) { + Order *auto_order = new Order(); + auto_order->MakeAutomatic(this->last_station_visited); + InsertOrder(this, auto_order, this->cur_order_index); + if (this->cur_order_index > 0) --this->cur_order_index; + } current_order.MakeLoading(false); } @@ -1808,11 +1826,8 @@ void Vehicle::HandleLoading(bool mode) this->PlayLeaveStationSound(); - bool at_destination_station = this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE; this->LeaveStation(); - /* If this was not the final order, don't remove it from the list. */ - if (!at_destination_station) return; break; } @@ -2143,6 +2158,20 @@ void Vehicle::RemoveFromShared() this->previous_shared = NULL; } +/** + * Get the next manual (not OT_AUTOMATIC) order after the one at the given index. + * @param index The index to start searching at. + * @return The next manual order at or after index or NULL if there is none. + */ +Order *Vehicle::GetNextManualOrder(int index) const +{ + Order *order = this->GetOrder(index); + while(order != NULL && order->IsType(OT_AUTOMATIC)) { + order = order->next; + } + return order; +} + void StopAllVehicles() { Vehicle *v; -- cgit v1.2.3-54-g00ecf