+int Train::get_entry_to_block(Block *block) const
+{
+ for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
+ if(i->block==block)
+ return i->entry;
+ for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+ if(i->block==block)
+ return i->entry;
+ return -1;
+}
+
+void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
+{
+ if(try_reserve && t>try_reserve)
+ reserve_more();
+
+ if(cur_track)
+ {
+ unsigned path = 0;
+ if(cur_track->get_turnout_id())
+ path = trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_path();
+
+ offset += get_real_speed(loco.get_speed())*(dt/Time::sec);
+ if(offset>cur_track->get_type().get_path_length(path))
+ {
+ int out = cur_track->traverse(cur_track_ep, path);
+ if(out>=0)
+ {
+ Track *next = cur_track->get_link(out);
+ if(next)
+ cur_track_ep = next->get_endpoint_by_link(*cur_track);
+ cur_track = next;
+ offset = 0;
+ }
+ else
+ cur_track = 0;
+ }
+
+ if(cur_track)
+ pos = cur_track->get_point(cur_track_ep, path, offset);
+ }
+}
+
+void Train::save(list<DataFile::Statement> &st) const
+{
+ st.push_back((DataFile::Statement("name"), name));
+ for(unsigned i=0; i<=14; ++i)
+ if(real_speed[i].weight)
+ st.push_back((DataFile::Statement("real_speed"), i, real_speed[i].speed, real_speed[i].weight));
+}
+
+void Train::locomotive_reverse_changed(bool)
+{
+ for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+ i->block->reserve(0);
+ rsv_blocks.clear();
+ cur_blocks.reverse();
+ for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
+ i->entry = i->block->traverse(i->entry);
+ reserve_more();
+
+ if(cur_track)
+ {
+ unsigned path = 0;
+ if(unsigned turnout = cur_track->get_turnout_id())
+ path = trfc_mgr.get_control().get_turnout(turnout).get_path();
+ cur_track_ep = cur_track->traverse(cur_track_ep, path);
+ offset = cur_track->get_type().get_path_length(path)-offset;
+ }
+}
+
+void Train::sensor_event(bool state, Sensor *sensor)