Changeset - r17702:bc20a4f6c920
[Not reviewed]
master
0 1 0
frosch - 13 years ago 2011-05-25 20:10:02
frosch@openttd.org
(svn r22492) -Fix [FS#4624] (r21642, r22328): Only try to insert implicit orders for ground vehicles. Aircraft may reach unscheduled terminals when skippnig orders etc.
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/vehicle.cpp
Show inline comments
 
@@ -1833,58 +1833,58 @@ void Vehicle::DeleteUnreachedImplicitOrd
 
/**
 
 * Prepare everything to begin the loading when arriving at a station.
 
 * @pre IsTileType(this->tile, MP_STATION) || this->type == VEH_SHIP.
 
 */
 
void Vehicle::BeginLoading()
 
{
 
	assert(IsTileType(this->tile, MP_STATION) || this->type == VEH_SHIP);
 

	
 
	if (this->current_order.IsType(OT_GOTO_STATION) &&
 
			this->current_order.GetDestination() == this->last_station_visited) {
 
		this->DeleteUnreachedImplicitOrders();
 

	
 
		/* Now both order indices point to the destination station, and we can start loading */
 
		this->current_order.MakeLoading(true);
 
		UpdateVehicleTimetable(this, true);
 

	
 
		/* 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
 
		 * whether the train is lost or not; not marking a train lost
 
		 * that arrives at random stations is bad. */
 
		this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
 

	
 
	} else {
 
		assert(this->IsGroundVehicle());
 
		bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS);
 

	
 
		/* We weren't scheduled to stop here. Insert an implicit order
 
		 * to show that we are stopping here, but only do that if the order
 
		 * list isn't empty. */
 
		 * list isn't empty.
 
		 * While only groundvehicles have implicit orders, e.g. aircraft might still enter
 
		 * the 'wrong' terminal when skipping orders etc. */
 
		Order *in_list = this->GetOrder(this->cur_implicit_order_index);
 
		if (in_list != NULL &&
 
		if (this->IsGroundVehicle() && in_list != NULL &&
 
				(!in_list->IsType(OT_IMPLICIT) ||
 
				in_list->GetDestination() != this->last_station_visited)) {
 
			bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS);
 
			/* Do not create consecutive duplicates of implicit orders */
 
			Order *prev_order = this->cur_implicit_order_index > 0 ? this->GetOrder(this->cur_implicit_order_index - 1) : NULL;
 
			if (prev_order == NULL ||
 
					(!prev_order->IsType(OT_IMPLICIT) && !prev_order->IsType(OT_GOTO_STATION)) ||
 
					prev_order->GetDestination() != this->last_station_visited) {
 

	
 
				/* Prefer deleting implicit orders instead of inserting new ones,
 
				 * so test whether the right order follows later */
 
				int target_index = this->cur_implicit_order_index;
 
				bool found = false;
 
				while (target_index != this->cur_real_order_index) {
 
					const Order *order = this->GetOrder(target_index);
 
					if (order->IsType(OT_IMPLICIT) && order->GetDestination() == this->last_station_visited) {
 
						found = true;
 
						break;
 
					}
 
					target_index++;
 
					if (target_index >= this->orders.list->GetNumOrders()) target_index = 0;
 
					assert(target_index != this->cur_implicit_order_index); // infinite loop?
 
				}
 

	
 
				if (found) {
 
					if (suppress_implicit_orders) {
 
						/* Skip to the found order */
0 comments (0 inline, 0 general)