summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-03-03 21:18:19 +0000
committertron <tron@openttd.org>2006-03-03 21:18:19 +0000
commit36467a4bcf6ef67f57e92a33fb6a674498b94ac1 (patch)
tree633463c0d010c1c84827d91c2c8f7e23e8af7d9a
parent2942939ad1e26b57766d546d99c7935ca89d9089 (diff)
downloadopenttd-36467a4bcf6ef67f57e92a33fb6a674498b94ac1.tar.xz
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
-rw-r--r--roadveh_cmd.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index e4b5ae6eb..4500664f7 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -633,8 +633,9 @@ static void ProcessRoadVehOrder(Vehicle *v)
if (order->type == OT_GOTO_STATION) {
const Station* st = GetStation(order->station);
- uint mindist = 0xFFFFFFFF;
const RoadStop* rs;
+ TileIndex dest;
+ uint mindist;
if (order->station == v->last_station_visited) {
v->last_station_visited = INVALID_STATION;
@@ -649,9 +650,17 @@ static void ProcessRoadVehOrder(Vehicle *v)
return;
}
- for (; rs != NULL; rs = rs->next) {
- if (DistanceManhattan(v->tile, rs->xy) < mindist) v->dest_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);
+
+ 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;
}