+void Train::go_to(const Track &to)
+{
+ BlockRef *last = 0;
+ if(rsv_blocks.empty())
+ last = &cur_blocks.back();
+ else
+ {
+ for(list<BlockRef>::iterator i=rsv_blocks.begin(); (i!=rsv_blocks.end() && !last); ++i)
+ if(i->block->get_sensor_id())
+ last = &*i;
+ }
+
+ Block *next = last->block->get_endpoints()[last->block->traverse(last->entry)].link;
+ if(!next)
+ throw InvalidState("At end of line");
+
+ int entry = next->get_endpoint_by_link(*last->block);
+ if(entry<0)
+ throw LogicError("Block links are inconsistent");
+
+ const Block::Endpoint &ep = next->get_endpoints()[entry];
+
+ set_route(Route::find(*ep.track, ep.track_ep, to));
+}
+