From 1856976d8e7c108ec453064cee83934c386d3ece Mon Sep 17 00:00:00 2001 From: Darkvater Date: Sat, 18 Mar 2006 15:45:23 +0000 Subject: [PATCH] (svn r3960) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list. Backport of r3751 from trunk --- roadveh_cmd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 535aced709..4db73d9d10 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -634,7 +634,8 @@ static void ProcessRoadVehOrder(Vehicle *v) st = GetStation(order->station); { - uint mindist = 0xFFFFFFFF; + TileIndex dest; + uint mindist; RoadStopType type; RoadStop *rs; @@ -649,12 +650,17 @@ static void ProcessRoadVehOrder(Vehicle *v) return; } - for (rs = GetPrimaryRoadStop(st, type); 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;