1
0
Fork 0

(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible

release/0.5
tron 2006-02-10 06:03:51 +00:00
parent 4f0ff156e8
commit 784801f930
1 changed files with 46 additions and 54 deletions

View File

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