# HG changeset patch # User tron # Date 1139551431 0 # Node ID 32d777e2353c2d69021ccd4908807db65d39ee14 # Parent 15a000f2b81d5134291f9edf5526b6aa0dcf22fe (svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible diff -r 15a000f2b81d -r 32d777e2353c roadveh_cmd.c --- a/roadveh_cmd.c Thu Feb 09 07:34:37 2006 +0000 +++ b/roadveh_cmd.c Fri Feb 10 06:03:51 2006 +0000 @@ -587,23 +587,23 @@ 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) { - // Let a depot order in the orderlist interrupt. - if (v->current_order.type != OT_GOTO_DEPOT || - !(v->current_order.flags & OF_UNLOAD)) + switch (v->current_order.type) { + case OT_GOTO_DEPOT: + // Let a depot order in the orderlist interrupt. + 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; + + case OT_LOADING: + case OT_LEAVESTATION: 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) && - !VehicleNeedsService(v)) { - v->cur_order_index++; - } - - if (v->cur_order_index >= v->num_orders) - v->cur_order_index = 0; + if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; order = GetVehicleOrder(v, v->cur_order_index); @@ -624,32 +624,25 @@ 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); - - { - uint mindist = 0xFFFFFFFF; - RoadStopType type; - RoadStop *rs; - - type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; - rs = GetPrimaryRoadStop(st, type); + const Station* st = GetStation(order->station); + uint mindist = 0xFFFFFFFF; + const RoadStop* rs; - 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); + if (order->station == v->last_station_visited) { + v->last_station_visited = INVALID_STATION; + } - return; - } + rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK); - for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) { - if (DistanceManhattan(v->tile, rs->xy) < mindist) { - v->dest_tile = rs->xy; - } - } + 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 != 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,32 +653,31 @@ static void HandleRoadVehLoading(Vehicle *v) { - if (v->current_order.type == OT_NOTHING) - return; - - if (v->current_order.type != OT_DUMMY) { - if (v->current_order.type != OT_LOADING) - return; + switch (v->current_order.type) { + case OT_LOADING: { + Order b; - 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); - if (LoadUnloadVehicle(v)) { - InvalidateWindow(WC_ROADVEH_LIST, v->owner); - MarkRoadVehDirty(v); + if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { + SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); + if (LoadUnloadVehicle(v)) { + InvalidateWindow(WC_ROADVEH_LIST, v->owner); + MarkRoadVehDirty(v); + } + return; } - return; + + b = v->current_order; + v->current_order.type = OT_LEAVESTATION; + v->current_order.flags = 0; + if (!(b.flags & OF_NON_STOP)) return; + break; } - { - Order b = v->current_order; - v->current_order.type = OT_LEAVESTATION; - v->current_order.flags = 0; - if (!(b.flags & OF_NON_STOP)) - return; - } + case OT_DUMMY: break; + + default: return; } v->cur_order_index++;