Changeset - r9559:e67d1ef57a67
[Not reviewed]
master
0 1 0
rubidium - 16 years ago 2008-06-19 11:45:52
rubidium@openttd.org
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
1 file changed with 8 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/order_cmd.cpp
Show inline comments
 
@@ -1635,25 +1635,25 @@ static VehicleOrderID ProcessConditional
 
		case OCV_UNCONDITIONALLY:  skip_order = true; break;
 
		default: NOT_REACHED();
 
	}
 

	
 
	return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID;
 
}
 

	
 
/**
 
 * Update the vehicle's destination tile from an order.
 
 * @param order the order the vehicle currently has
 
 * @param v the vehicle to update
 
 */
 
static bool UpdateOrderDest(Vehicle *v, const Order *order)
 
static bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth = 0)
 
{
 
	switch (order->GetType()) {
 
		case OT_GOTO_STATION:
 
			v->dest_tile = v->GetOrderStationLocation(order->GetDestination());
 
			break;
 

	
 
		case OT_GOTO_DEPOT:
 
			if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
 
				/* We need to search for the nearest depot (hangar). */
 
				TileIndex location;
 
				DestinationID destination;
 
				bool reverse;
 
@@ -1682,25 +1682,31 @@ static bool UpdateOrderDest(Vehicle *v, 
 
		case OT_GOTO_WAYPOINT:
 
			v->dest_tile = GetWaypoint(order->GetDestination())->xy;
 
			break;
 

	
 
		case OT_CONDITIONAL: {
 
			VehicleOrderID next_order = ProcessConditionalOrder(order, v);
 
			UpdateVehicleTimetable(v, true);
 
			if (next_order != INVALID_VEH_ORDER_ID) {
 
				v->cur_order_index = next_order;
 
			} else {
 
				v->cur_order_index++;
 
			}
 
			return false;
 

	
 
			if (conditional_depth > v->num_orders) return false;
 

	
 
			/* Get the current order */
 
			if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
 

	
 
			return UpdateOrderDest(v, GetVehicleOrder(v, v->cur_order_index), conditional_depth + 1);
 
		}
 

	
 
		default:
 
			v->dest_tile = 0;
 
			return false;
 
	}
 
	return true;
 
}
 

	
 
/**
 
 * Handle the orders of a vehicle and determine the next place
 
 * to go to if needed.
0 comments (0 inline, 0 general)