Changeset - r21304:421b0c8bcef3
[Not reviewed]
master
0 3 0
fonsinchen - 11 years ago 2014-03-06 21:19:41
fonsinchen@openttd.org
(svn r26393) -Fix: Update distances between link graph nodes when station sign is moved
3 files changed with 24 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/linkgraph/linkgraph.cpp
Show inline comments
 
@@ -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
src/linkgraph/linkgraph.h
Show inline comments
 
@@ -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;
src/station_cmd.cpp
Show inline comments
 
@@ -641,6 +641,14 @@ static void UpdateStationSignCoord(BaseS
 
	/* clamp sign coord to be inside the station rect */
 
	st->xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
 
	st->UpdateVirtCoord();
 

	
 
	if (!Station::IsExpected(st)) return;
 
	Station *full_station = Station::From(st);
 
	for (CargoID c = 0; c < NUM_CARGO; ++c) {
 
		LinkGraphID lg = full_station->goods[c].link_graph;
 
		if (!LinkGraph::IsValidID(lg)) continue;
 
		LinkGraph::Get(lg)->UpdateDistances(full_station->goods[c].node, st->xy);
 
	}
 
}
 

	
 
/**
0 comments (0 inline, 0 general)