summaryrefslogtreecommitdiff
path: root/src/linkgraph
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-11-07 20:50:03 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-11-07 20:50:03 +0000
commitf6fd21e8e668860086b41aec7a939bd7b027f162 (patch)
tree14e6e655c5df0e20f0d1f6a24d198e64e2f0685a /src/linkgraph
parentfbceb10ff51e73fe8096a171c43cc98f20f56fc8 (diff)
downloadopenttd-f6fd21e8e668860086b41aec7a939bd7b027f162.tar.xz
(svn r25948) -Fix [FS#5796]: Make sure LinkRefresher doesn't delete the LinkGraph DeleteStaleLinks() is examining.
Diffstat (limited to 'src/linkgraph')
-rw-r--r--src/linkgraph/refresh.cpp23
-rw-r--r--src/linkgraph/refresh.h5
2 files changed, 21 insertions, 7 deletions
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp
index 53a1d28df..5fda84cea 100644
--- a/src/linkgraph/refresh.cpp
+++ b/src/linkgraph/refresh.cpp
@@ -20,8 +20,9 @@
/**
* Refresh all links the given vehicle will visit.
* @param v Vehicle to refresh links for.
+ * @param allow_merge If the refresher is allowed to merge or extend link graphs.
*/
-/* static */ void LinkRefresher::Run(Vehicle *v)
+/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge)
{
/* If there are no orders we can't predict anything.*/
if (v->orders.list == NULL) return;
@@ -31,7 +32,7 @@
if (first == NULL) return;
HopSet seen_hops;
- LinkRefresher refresher(v, &seen_hops);
+ LinkRefresher refresher(v, &seen_hops, allow_merge);
refresher.RefreshLinks(first, first, v->last_loading_station != INVALID_STATION ? 1 << HAS_CARGO : 0);
}
@@ -59,9 +60,12 @@ bool LinkRefresher::Hop::operator<(const Hop &other) const
/**
* Constructor for link refreshing algorithm.
* @param vehicle Vehicle to refresh links for.
+ * @param seen_hops Set of hops already seen. This is shared between this
+ * refresher and all its children.
+ * @param allow_merge If the refresher is allowed to merge or extend link graphs.
*/
-LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops) :
- vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID)
+LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge) :
+ vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge)
{
/* Assemble list of capacities and set last loading stations to 0. */
for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
@@ -190,10 +194,19 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
if (st != NULL && next_station != INVALID_STATION && next_station != st->index) {
for (CapacitiesMap::const_iterator i = this->capacities.begin(); i != this->capacities.end(); ++i) {
/* Refresh the link and give it a minimum capacity. */
+
if (i->second == 0) continue;
+ CargoID c = i->first;
+
+ /* If not allowed to merge link graphs, make sure the stations are
+ * already in the same link graph. */
+ if (!this->allow_merge && st->goods[c].link_graph != Station::Get(next_station)->goods[c].link_graph) {
+ continue;
+ }
+
/* A link is at least partly restricted if a
* vehicle can't load at its source. */
- IncreaseStats(st, i->first, next_station, i->second,
+ IncreaseStats(st, c, next_station, i->second,
(cur->GetLoadType() & OLFB_NO_LOAD) == 0 ? LinkGraph::REFRESH_UNRESTRICTED : LinkGraph::REFRESH_RESTRICTED);
}
}
diff --git a/src/linkgraph/refresh.h b/src/linkgraph/refresh.h
index aa3d8850d..21c92c4bc 100644
--- a/src/linkgraph/refresh.h
+++ b/src/linkgraph/refresh.h
@@ -23,7 +23,7 @@
*/
class LinkRefresher {
public:
- static void Run(Vehicle *v);
+ static void Run(Vehicle *v, bool allow_merge = true);
protected:
/**
@@ -87,8 +87,9 @@ protected:
RefitList refit_capacities; ///< Current state of capacity remaining from previous refits versus overall capacity per vehicle in the consist.
HopSet *seen_hops; ///< Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Refreshers of the same run.
CargoID cargo; ///< Cargo given in last refit order.
+ bool allow_merge; ///< If the refresher is allowed to merge or extend link graphs.
- LinkRefresher(Vehicle *v, HopSet *seen_hops);
+ LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge);
void HandleRefit(const Order *next);
void ResetRefit();