From 930c19dae292d5863b201ded98444c9fb2e7b20a Mon Sep 17 00:00:00 2001 From: fonsinchen Date: Sun, 23 Jun 2013 08:29:28 +0000 Subject: (svn r25435) -Fix: reroute cargo in vehicles if station is deleted --- src/station_cmd.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/station_cmd.cpp') diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2335d8151..75c473e22 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3377,6 +3377,30 @@ static void UpdateStationRating(Station *st) } } +/** + * Reroute cargo of type c at station st or in any vehicles unloading there. + * Make sure the cargo's new next hop is neither "avoid" nor "avoid2". + * @param st Station to be rerouted at. + * @param c Type of cargo. + * @param avoid Original next hop of cargo, avoid this. + * @param avoid2 Another station to be avoided when rerouting. + */ +void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2) +{ + GoodsEntry &ge = st->goods[c]; + + /* Reroute cargo in station. */ + ge.cargo.Reroute(UINT_MAX, &ge.cargo, avoid, avoid2, &ge); + + /* Reroute cargo staged to be transfered. */ + for (std::list::iterator it(st->loading_vehicles.begin()); it != st->loading_vehicles.end(); ++it) { + for (Vehicle *v = *it; v != NULL; v = v->Next()) { + if (v->cargo_type != c) continue; + v->cargo.Reroute(UINT_MAX, &v->cargo, avoid, avoid2, &ge); + } + } +} + /** * Check all next hops of cargo packets in this station for existance of a * a valid link they may use to travel on. Reroute any cargo not having a valid @@ -3402,17 +3426,7 @@ void DeleteStaleLinks(Station *from) (DistanceManhattan(from->xy, to->xy) >> 2)) { node.RemoveEdge(to->goods[c].node); ge.flows.DeleteFlows(to->index); - - /* Reroute cargo in station. */ - ge.cargo.Reroute(UINT_MAX, &ge.cargo, to->index, from->index, &ge); - - /* Reroute cargo staged to be transfered. */ - for (std::list::iterator it(from->loading_vehicles.begin()); it != from->loading_vehicles.end(); ++it) { - for (Vehicle *v = *it; v != NULL; v = v->Next()) { - if (v->cargo_type != c) continue; - v->cargo.Reroute(UINT_MAX, &v->cargo, to->index, from->index, &ge); - } - } + RerouteCargo(from, c, to->index, from->index); } } assert(_date >= lg->LastCompression()); -- cgit v1.2.3-54-g00ecf