diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -21,11 +21,13 @@ INSTANTIATE_POOL_METHODS(LinkGraph) /** * Create a node or clear it. + * @param xy Location of the associated station. * @param st ID of the associated station. * @param demand Demand for cargo at the station. */ -inline void LinkGraph::BaseNode::Init(StationID st, uint demand) +inline void LinkGraph::BaseNode::Init(TileIndex xy, StationID st, uint demand) { + this->xy = xy; this->supply = 0; this->demand = demand; this->station = st; @@ -34,11 +36,9 @@ inline void LinkGraph::BaseNode::Init(St /** * Create an edge. - * @param distance Length of the link as manhattan distance. */ -inline void LinkGraph::BaseEdge::Init(uint distance) +inline void LinkGraph::BaseEdge::Init() { - this->distance = distance; this->capacity = 0; this->usage = 0; this->last_unrestricted_update = INVALID_DATE; @@ -147,21 +147,6 @@ 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 = - DistanceMaxPlusManhattan(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 @@ -180,7 +165,7 @@ NodeID LinkGraph::AddNode(const Station this->edges.Resize(new_node + 1U, max(new_node + 1U, this->edges.Height())); - this->nodes[new_node].Init(st->index, + this->nodes[new_node].Init(st->xy, st->index, HasBit(good.status, GoodsEntry::GES_ACCEPTANCE)); BaseEdge *new_edges = this->edges[new_node]; @@ -189,9 +174,8 @@ NodeID LinkGraph::AddNode(const Station new_edges[new_node].next_edge = INVALID_NODE; for (NodeID i = 0; i <= new_node; ++i) { - uint distance = DistanceMaxPlusManhattan(st->xy, Station::Get(this->nodes[i].station)->xy); - new_edges[i].Init(distance); - this->edges[i][new_node].Init(distance); + new_edges[i].Init(); + this->edges[i][new_node].Init(); } return new_node; }