diff options
author | fonsinchen <fonsinchen@openttd.org> | 2014-03-06 21:19:41 +0000 |
---|---|---|
committer | fonsinchen <fonsinchen@openttd.org> | 2014-03-06 21:19:41 +0000 |
commit | 5d3fcce72596dddbaac3229b400bfc9023489e1c (patch) | |
tree | 6e9913649c61679d720ff567632b42e357e20542 /src/linkgraph | |
parent | aee9444c1bdfbc589c99fd2daf3c61868cb7fa4b (diff) | |
download | openttd-5d3fcce72596dddbaac3229b400bfc9023489e1c.tar.xz |
(svn r26393) -Fix: Update distances between link graph nodes when station sign is moved
Diffstat (limited to 'src/linkgraph')
-rw-r--r-- | src/linkgraph/linkgraph.cpp | 15 | ||||
-rw-r--r-- | src/linkgraph/linkgraph.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp index 6bd29c92d..e8c792c37 100644 --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -145,6 +145,21 @@ void LinkGraph::RemoveNode(NodeID id) } /** + * Update distances between the given node and all others. + * @param id Node that changed position. + * @param xy New position of the node. + */ +void LinkGraph::UpdateDistances(NodeID id, TileIndex xy) +{ + assert(id < this->Size()); + for (NodeID other = 0; other < this->Size(); ++other) { + if (other == id) continue; + this->edges[id][other].distance = this->edges[other][id].distance = + DistanceManhattan(xy, Station::Get(this->nodes[other].station)->xy); + } +} + +/** * Add a node to the component and create empty edges associated with it. Set * the station's last_component to this component. Calculate the distances to all * other nodes. The distances to _all_ nodes are important as the demand diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h index 4bcc27b31..4306ad2b3 100644 --- a/src/linkgraph/linkgraph.h +++ b/src/linkgraph/linkgraph.h @@ -529,6 +529,7 @@ public: NodeID AddNode(const Station *st); void RemoveNode(NodeID id); + void UpdateDistances(NodeID id, TileIndex xy); protected: friend class LinkGraph::ConstNode; |