mirror of https://github.com/OpenTTD/OpenTTD
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
parent
08720b6fd7
commit
c91a2e0f26
|
@ -633,8 +633,9 @@ static void ProcessRoadVehOrder(Vehicle *v)
|
||||||
|
|
||||||
if (order->type == OT_GOTO_STATION) {
|
if (order->type == OT_GOTO_STATION) {
|
||||||
const Station* st = GetStation(order->station);
|
const Station* st = GetStation(order->station);
|
||||||
uint mindist = 0xFFFFFFFF;
|
|
||||||
const RoadStop* rs;
|
const RoadStop* rs;
|
||||||
|
TileIndex dest;
|
||||||
|
uint mindist;
|
||||||
|
|
||||||
if (order->station == v->last_station_visited) {
|
if (order->station == v->last_station_visited) {
|
||||||
v->last_station_visited = INVALID_STATION;
|
v->last_station_visited = INVALID_STATION;
|
||||||
|
@ -649,9 +650,17 @@ static void ProcessRoadVehOrder(Vehicle *v)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; rs != NULL; rs = rs->next) {
|
dest = rs->xy;
|
||||||
if (DistanceManhattan(v->tile, rs->xy) < mindist) v->dest_tile = 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) {
|
} else if (order->type == OT_GOTO_DEPOT) {
|
||||||
v->dest_tile = GetDepot(order->station)->xy;
|
v->dest_tile = GetDepot(order->station)->xy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue