summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2014-01-29 19:55:29 +0000
committerfonsinchen <fonsinchen@openttd.org>2014-01-29 19:55:29 +0000
commit91407b924ea47efdfe3a17fad5513189d5605288 (patch)
tree26ab6e02883efd83b884c177e65a1e4eab94320b
parente4a4f2c1ddbc67aa9d5fa7380a8eb2a10b619958 (diff)
downloadopenttd-91407b924ea47efdfe3a17fad5513189d5605288.tar.xz
(svn r26286) -Fix: Thoroughly erase dead flows.
-rw-r--r--src/linkgraph/linkgraphjob.cpp23
-rw-r--r--src/linkgraph/linkgraphjob.h2
-rw-r--r--src/station.cpp3
3 files changed, 24 insertions, 4 deletions
diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp
index 717a7305d..318186d3f 100644
--- a/src/linkgraph/linkgraphjob.cpp
+++ b/src/linkgraph/linkgraphjob.cpp
@@ -35,6 +35,17 @@ LinkGraphJob::LinkGraphJob(const LinkGraph &orig) :
}
/**
+ * Erase all flows originating at a specific node.
+ * @param from Node to erase flows for.
+ */
+void LinkGraphJob::EraseFlows(NodeID from)
+{
+ for (NodeID node_id = 0; node_id < this->Size(); ++node_id) {
+ (*this)[node_id].Flows().erase(from);
+ }
+}
+
+/**
* Join the link graph job and destroy it.
*/
LinkGraphJob::~LinkGraphJob()
@@ -52,14 +63,20 @@ LinkGraphJob::~LinkGraphJob()
for (NodeID node_id = 0; node_id < size; ++node_id) {
Node from = (*this)[node_id];
- /* The station can have been deleted. */
+ /* The station can have been deleted. Remove all flows originating from it then. */
Station *st = Station::GetIfValid(from.Station());
- if (st == NULL) continue;
+ if (st == NULL) {
+ this->EraseFlows(node_id);
+ continue;
+ }
/* Link graph merging and station deletion may change around IDs. Make
* sure that everything is still consistent or ignore it otherwise. */
GoodsEntry &ge = st->goods[this->Cargo()];
- if (ge.link_graph != this->link_graph.index || ge.node != node_id) continue;
+ if (ge.link_graph != this->link_graph.index || ge.node != node_id) {
+ this->EraseFlows(node_id);
+ continue;
+ }
LinkGraph *lg = LinkGraph::Get(ge.link_graph);
FlowStatMap &flows = from.Flows();
diff --git a/src/linkgraph/linkgraphjob.h b/src/linkgraph/linkgraphjob.h
index 66aff3672..f6979db74 100644
--- a/src/linkgraph/linkgraphjob.h
+++ b/src/linkgraph/linkgraphjob.h
@@ -64,6 +64,8 @@ protected:
NodeAnnotationVector nodes; ///< Extra node data necessary for link graph calculation.
EdgeAnnotationMatrix edges; ///< Extra edge data necessary for link graph calculation.
+ void EraseFlows(NodeID from);
+
public:
/**
diff --git a/src/station.cpp b/src/station.cpp
index 0c7af914b..30723cc7b 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -99,8 +99,9 @@ Station::~Station()
if (lg == NULL) continue;
for (NodeID node = 0; node < lg->Size(); ++node) {
+ Station *st = Station::Get((*lg)[node].Station());
+ st->goods[c].flows.erase(this->index);
if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
- Station *st = Station::Get((*lg)[node].Station());
st->goods[c].flows.DeleteFlows(this->index);
RerouteCargo(st, c, this->index, st->index);
}