(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
This commit is contained in:
		@@ -587,23 +587,23 @@ static void HandleBrokenRoadVeh(Vehicle *v)
 | 
			
		||||
static void ProcessRoadVehOrder(Vehicle *v)
 | 
			
		||||
{
 | 
			
		||||
	const Order *order;
 | 
			
		||||
	const Station *st;
 | 
			
		||||
 | 
			
		||||
	if (v->current_order.type >= OT_GOTO_DEPOT && v->current_order.type <= OT_LEAVESTATION) {
 | 
			
		||||
	switch (v->current_order.type) {
 | 
			
		||||
		case OT_GOTO_DEPOT:
 | 
			
		||||
			// Let a depot order in the orderlist interrupt.
 | 
			
		||||
		if (v->current_order.type != OT_GOTO_DEPOT ||
 | 
			
		||||
				!(v->current_order.flags & OF_UNLOAD))
 | 
			
		||||
			return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (v->current_order.type == OT_GOTO_DEPOT &&
 | 
			
		||||
			(v->current_order.flags & (OF_PART_OF_ORDERS | OF_SERVICE_IF_NEEDED)) == (OF_PART_OF_ORDERS | OF_SERVICE_IF_NEEDED) &&
 | 
			
		||||
			if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return;
 | 
			
		||||
			if (v->current_order.flags & OF_SERVICE_IF_NEEDED &&
 | 
			
		||||
					!VehicleNeedsService(v)) {
 | 
			
		||||
				v->cur_order_index++;
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
	if (v->cur_order_index >= v->num_orders)
 | 
			
		||||
		v->cur_order_index = 0;
 | 
			
		||||
		case OT_LOADING:
 | 
			
		||||
		case OT_LEAVESTATION:
 | 
			
		||||
			return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
 | 
			
		||||
 | 
			
		||||
	order = GetVehicleOrder(v, v->cur_order_index);
 | 
			
		||||
 | 
			
		||||
@@ -624,32 +624,25 @@ static void ProcessRoadVehOrder(Vehicle *v)
 | 
			
		||||
	v->dest_tile = 0;
 | 
			
		||||
 | 
			
		||||
	if (order->type == OT_GOTO_STATION) {
 | 
			
		||||
		if (order->station == v->last_station_visited)
 | 
			
		||||
			v->last_station_visited = INVALID_STATION;
 | 
			
		||||
		st = GetStation(order->station);
 | 
			
		||||
 | 
			
		||||
		{
 | 
			
		||||
		const Station* st = GetStation(order->station);
 | 
			
		||||
		uint mindist = 0xFFFFFFFF;
 | 
			
		||||
			RoadStopType type;
 | 
			
		||||
			RoadStop *rs;
 | 
			
		||||
		const RoadStop* rs;
 | 
			
		||||
 | 
			
		||||
			type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK;
 | 
			
		||||
			rs = GetPrimaryRoadStop(st, type);
 | 
			
		||||
		if (order->station == v->last_station_visited) {
 | 
			
		||||
			v->last_station_visited = INVALID_STATION;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK);
 | 
			
		||||
 | 
			
		||||
		if (rs == NULL) {
 | 
			
		||||
			// There is no stop left at the station, so don't even TRY to go there
 | 
			
		||||
			v->cur_order_index++;
 | 
			
		||||
			InvalidateVehicleOrder(v);
 | 
			
		||||
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
			for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) {
 | 
			
		||||
				if (DistanceManhattan(v->tile, rs->xy) < mindist) {
 | 
			
		||||
					v->dest_tile = rs->xy;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		for (; rs != NULL; rs = rs->next) {
 | 
			
		||||
			if (DistanceManhattan(v->tile, rs->xy) < mindist) v->dest_tile = rs->xy;
 | 
			
		||||
		}
 | 
			
		||||
	} else if (order->type == OT_GOTO_DEPOT) {
 | 
			
		||||
		v->dest_tile = GetDepot(order->station)->xy;
 | 
			
		||||
@@ -660,15 +653,11 @@ static void ProcessRoadVehOrder(Vehicle *v)
 | 
			
		||||
 | 
			
		||||
static void HandleRoadVehLoading(Vehicle *v)
 | 
			
		||||
{
 | 
			
		||||
	if (v->current_order.type == OT_NOTHING)
 | 
			
		||||
		return;
 | 
			
		||||
	switch (v->current_order.type) {
 | 
			
		||||
		case OT_LOADING: {
 | 
			
		||||
			Order b;
 | 
			
		||||
 | 
			
		||||
	if (v->current_order.type != OT_DUMMY) {
 | 
			
		||||
		if (v->current_order.type != OT_LOADING)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		if (--v->load_unload_time_rem)
 | 
			
		||||
			return;
 | 
			
		||||
			if (--v->load_unload_time_rem != 0) return;
 | 
			
		||||
 | 
			
		||||
			if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) {
 | 
			
		||||
				SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
 | 
			
		||||
@@ -679,13 +668,16 @@ static void HandleRoadVehLoading(Vehicle *v)
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		{
 | 
			
		||||
			Order b = v->current_order;
 | 
			
		||||
			b = v->current_order;
 | 
			
		||||
			v->current_order.type = OT_LEAVESTATION;
 | 
			
		||||
			v->current_order.flags = 0;
 | 
			
		||||
			if (!(b.flags & OF_NON_STOP))
 | 
			
		||||
				return;
 | 
			
		||||
			if (!(b.flags & OF_NON_STOP)) return;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		case OT_DUMMY: break;
 | 
			
		||||
 | 
			
		||||
		default: return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	v->cur_order_index++;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user