summaryrefslogtreecommitdiff
path: root/roadveh_cmd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-07-26 10:50:46 +0000
committertron <tron@openttd.org>2006-07-26 10:50:46 +0000
commitfbcdf3c24e3ce0f60cf484bfd402d5618c40a62c (patch)
treead0eae868f1f8e8bb414cbf330a31d02388731e3 /roadveh_cmd.c
parent4612836b404ed97008550229ca51d5b9962f27ce (diff)
downloadopenttd-fbcdf3c24e3ce0f60cf484bfd402d5618c40a62c.tar.xz
(svn r5617) if cascade -> switch
Diffstat (limited to 'roadveh_cmd.c')
-rw-r--r--roadveh_cmd.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index b276b34ae..f701937c4 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -641,40 +641,48 @@ static void ProcessRoadVehOrder(Vehicle *v)
}
v->current_order = *order;
- v->dest_tile = 0;
- if (order->type == OT_GOTO_STATION) {
- const Station* st = GetStation(order->station);
- const RoadStop* rs;
- TileIndex dest;
- uint mindist;
+ switch (order->type) {
+ case OT_GOTO_STATION: {
+ const RoadStop* rs;
- if (order->station == v->last_station_visited) {
- v->last_station_visited = INVALID_STATION;
- }
+ 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);
+ rs = GetPrimaryRoadStop(
+ GetStation(order->station),
+ 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;
- }
+ if (rs != NULL) {
+ TileIndex dest = rs->xy;
+ uint mindist = DistanceManhattan(v->tile, rs->xy);
- 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);
+ for (rs = rs->next; rs != NULL; rs = rs->next) {
+ uint dist = DistanceManhattan(v->tile, rs->xy);
- if (dist < mindist) {
- mindist = dist;
- dest = rs->xy;
+ 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;
}
- v->dest_tile = dest;
- } else if (order->type == OT_GOTO_DEPOT) {
- v->dest_tile = GetDepot(order->station)->xy;
+
+ case OT_GOTO_DEPOT:
+ v->dest_tile = GetDepot(order->station)->xy;
+ break;
+
+ default:
+ v->dest_tile = 0;
+ break;
}
InvalidateVehicleOrder(v);