+unsigned Train::find_speed(float real) const
+{
+ if(real<=real_speed[0].speed)
+ return 0;
+
+ unsigned low = 0;
+ unsigned high = 0;
+ for(unsigned i=0; (!high && i<=14); ++i)
+ if(real_speed[i].weight)
+ {
+ if(real_speed[i].speed<real)
+ low = i;
+ else
+ high = i;
+ }
+ if(!high)
+ {
+ if(!low)
+ return 0;
+ return min(static_cast<unsigned>(low*real/real_speed[low].speed), 14U);
+ }
+
+ float f = (real-real_speed[low].speed)/(real_speed[high].speed-real_speed[low].speed);
+ return static_cast<unsigned>(low*(1-f)+high*f+0.5);
+}
+
+void Train::set_status(const string &s)
+{
+ status = s;
+ signal_status_changed.emit(s);
+}
+
+void Train::set_position(const Block::Endpoint &bep)
+{
+ cur_track = bep.track;
+ cur_track_ep = bep.track_ep;
+ offset = 0;
+ pos = cur_track->get_endpoint_position(cur_track_ep);
+}
+
+void Train::release_reserved_blocks()
+{
+ for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+ i->block->reserve(0);
+ rsv_blocks.clear();
+}
+
+
+Train::RealSpeed::RealSpeed():
+ speed(0),
+ weight(0)
+{ }
+
+void Train::RealSpeed::add(float s, float w)
+{
+ speed = (speed*weight+s*w)/(weight+w);
+ weight = min(weight+w, 300.0f);
+}
+
+
+Train::Loader::Loader(Train &t):
+ DataFile::BasicLoader<Train>(t)
+{
+ add("name", &Train::name);
+ add("real_speed", &Loader::real_speed);
+}
+
+void Train::Loader::real_speed(unsigned i, float speed, float weight)
+{
+ obj.real_speed[i].speed = speed;
+ obj.real_speed[i].weight = weight;