Mercurial > hg > openttd
changeset 4179:ee520257fa9d draft
(svn r5617) if cascade -> switch
author | tron <tron@openttd.org> |
---|---|
date | Wed, 26 Jul 2006 10:50:46 +0000 |
parents | 2b5e7677cacf |
children | 91f70f748e26 |
files | roadveh_cmd.c |
diffstat | 1 files changed, 37 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -641,40 +641,48 @@ } v->current_order = *order; - v->dest_tile = 0; + + switch (order->type) { + case OT_GOTO_STATION: { + const RoadStop* rs; + + if (order->station == v->last_station_visited) { + v->last_station_visited = INVALID_STATION; + } + + rs = GetPrimaryRoadStop( + GetStation(order->station), + v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK + ); - if (order->type == OT_GOTO_STATION) { - const Station* st = GetStation(order->station); - const RoadStop* rs; - TileIndex dest; - uint mindist; + if (rs != NULL) { + TileIndex dest = rs->xy; + uint mindist = DistanceManhattan(v->tile, rs->xy); + + for (rs = rs->next; rs != NULL; rs = rs->next) { + uint dist = DistanceManhattan(v->tile, rs->xy); - if (order->station == v->last_station_visited) { - v->last_station_visited = INVALID_STATION; + if (dist < mindist) { + mindist = dist; + dest = rs->xy; + } + } + v->dest_tile = dest; + } else { + // There is no stop left at the station, so don't even TRY to go there + v->cur_order_index++; + v->dest_tile = 0; + } + break; } - 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; - } + case OT_GOTO_DEPOT: + v->dest_tile = GetDepot(order->station)->xy; + break; - dest = rs->xy; - mindist = DistanceManhattan(v->tile, rs->xy); - for (rs = rs->next; rs != NULL; rs = rs->next) { - uint dist = DistanceManhattan(v->tile, rs->xy); - - if (dist < mindist) { - mindist = dist; - dest = rs->xy; - } - } - v->dest_tile = dest; - } else if (order->type == OT_GOTO_DEPOT) { - v->dest_tile = GetDepot(order->station)->xy; + default: + v->dest_tile = 0; + break; } InvalidateVehicleOrder(v);