+float Train::get_reserved_distance_until(const Block *until_block, bool back) const
+{
+ if(cur_blocks.empty())
+ return 0;
+
+ Vehicle &veh = *(reverse!=back ? vehicles.back() : vehicles.front());
+ const VehicleType &vtype = veh.get_type();
+
+ Track *track = veh.get_track();
+ if(!track)
+ return 0;
+
+ list<BlockRef>::const_iterator block = cur_blocks.begin();
+ while(block!=cur_blocks.end() && !block->block->get_tracks().count(track))
+ ++block;
+ if(block==cur_blocks.end() || block->block==until_block)
+ return 0;
+
+ unsigned entry = veh.get_entry();
+
+ float result = veh.get_offset();
+ if(reverse!=back)
+ entry = track->traverse(entry);
+ else
+ result = track->get_type().get_path_length(track->get_active_path())-result;
+ result -= vtype.get_length()/2;
+
+ while(1)
+ {
+ if(track->get_type().get_endpoints().size()<2)
+ break;
+
+ Track *next = track->get_link(track->traverse(entry));
+
+ if(!block->block->get_tracks().count(next))
+ {
+ if(back)
+ {
+ if(block==cur_blocks.begin())
+ break;
+ --block;
+ }
+ else
+ {
+ ++block;
+ if(block==cur_blocks.end())
+ block = rsv_blocks.begin();
+ if(block==rsv_blocks.end())
+ break;
+ }
+
+ if(block->block==until_block)
+ break;
+ }
+
+ entry = next->get_endpoint_by_link(*track);
+ track = next;
+
+ result += track->get_type().get_path_length(track->get_active_path());
+ }
+
+ return result;
+}
+