|
@@ -3456,14 +3456,14 @@ void DeleteStaleLinks(Station *from)
|
|
|
++it; // Do that before removing the edge. Anything else may crash.
|
|
|
assert(_date >= edge.LastUpdate());
|
|
|
uint timeout = LinkGraph::MIN_TIMEOUT_DISTANCE + (DistanceManhattan(from->xy, to->xy) >> 3);
|
|
|
if ((uint)(_date - edge.LastUpdate()) > timeout) {
|
|
|
/* Have all vehicles refresh their next hops before deciding to
|
|
|
* remove the node. */
|
|
|
bool updated = false;
|
|
|
OrderList *l;
|
|
|
SmallVector<Vehicle *, 32> vehicles;
|
|
|
FOR_ALL_ORDER_LISTS(l) {
|
|
|
bool found_from = false;
|
|
|
bool found_to = false;
|
|
|
for (Order *order = l->GetFirstOrder(); order != NULL; order = order->next) {
|
|
|
if (!order->IsType(OT_GOTO_STATION) && !order->IsType(OT_IMPLICIT)) continue;
|
|
|
if (order->GetDestination() == from->index) {
|
|
@@ -3472,24 +3472,37 @@ void DeleteStaleLinks(Station *from)
|
|
|
} else if (order->GetDestination() == to->index) {
|
|
|
found_to = true;
|
|
|
if (found_from) break;
|
|
|
}
|
|
|
}
|
|
|
if (!found_to || !found_from) continue;
|
|
|
for (Vehicle *v = l->GetFirstSharedVehicle(); !updated && v != NULL; v = v->NextShared()) {
|
|
|
/* There is potential for optimization here:
|
|
|
* - Usually consists of the same order list are the same. It's probably better to
|
|
|
* first check the first of each list, then the second of each list and so on.
|
|
|
* - We could try to figure out if we've seen a consist with the same cargo on the
|
|
|
* same list already and if the consist can actually carry the cargo we're looking
|
|
|
* for. With conditional and refit orders this is not quite trivial, though. */
|
|
|
LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
|
|
|
if (edge.LastUpdate() == _date) updated = true;
|
|
|
*(vehicles.Append()) = l->GetFirstSharedVehicle();
|
|
|
}
|
|
|
|
|
|
bool updated = false;
|
|
|
Vehicle **iter = vehicles.Begin();
|
|
|
while (iter != vehicles.End()) {
|
|
|
Vehicle *v = *iter;
|
|
|
|
|
|
LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
|
|
|
if (edge.LastUpdate() == _date) {
|
|
|
updated = true;
|
|
|
break;
|
|
|
}
|
|
|
if (updated) break;
|
|
|
|
|
|
Vehicle *next_shared = v->NextShared();
|
|
|
if (next_shared) {
|
|
|
*iter = next_shared;
|
|
|
++iter;
|
|
|
} else {
|
|
|
vehicles.Erase(iter);
|
|
|
}
|
|
|
|
|
|
if (iter == vehicles.End()) iter = vehicles.Begin();
|
|
|
}
|
|
|
|
|
|
if (!updated) {
|
|
|
/* If it's still considered dead remove it. */
|
|
|
node.RemoveEdge(to->goods[c].node);
|
|
|
ge.flows.DeleteFlows(to->index);
|
|
|
RerouteCargo(from, c, to->index, from->index);
|
|
|
}
|