diff options
author | rubidium <rubidium@openttd.org> | 2010-12-26 09:03:19 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-26 09:03:19 +0000 |
commit | 64f04c3a74be3769a3e0bbf2e1c68bd27d6579eb (patch) | |
tree | 8608582c367f18f6c6669751ca8f0374e9f6a54d /src/vehicle.cpp | |
parent | 8a278f771163b11074d23a573840af7b945abb8c (diff) | |
download | openttd-64f04c3a74be3769a3e0bbf2e1c68bd27d6579eb.tar.xz |
(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
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
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; |