]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/train.cpp
Handle vehicle positioning while going backwards
[r2c2.git] / source / libmarklin / train.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <cmath>
9 #include <msp/strings/formatter.h>
10 #include <msp/time/units.h>
11 #include <msp/time/utils.h>
12 #include "driver.h"
13 #include "layout.h"
14 #include "locotype.h"
15 #include "route.h"
16 #include "tracktype.h"
17 #include "train.h"
18 #include "vehicle.h"
19
20 using namespace std;
21 using namespace Msp;
22
23 namespace Marklin {
24
25 Train::Train(Layout &l, const LocoType &t, unsigned a):
26         layout(l),
27         loco_type(t),
28         address(a),
29         pending_block(0),
30         target_speed(0),
31         current_speed(0),
32         reverse(false),
33         functions(0),
34         route(0),
35         next_route(0),
36         end_of_route(false),
37         status("Unplaced"),
38         travel_dist(0),
39         travel_speed(0),
40         pure_speed(false),
41         real_speed(15)
42 {
43         vehicles.push_back(new Vehicle(layout, loco_type));
44
45         layout.add_train(*this);
46
47         layout.get_driver().add_loco(address);
48         layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event));
49         layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event));
50
51         layout.signal_block_reserved.connect(sigc::mem_fun(this, &Train::block_reserved));
52         layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Train::sensor_event));
53         layout.get_driver().signal_turnout.connect(sigc::mem_fun(this, &Train::turnout_event));
54 }
55
56 Train::~Train()
57 {
58         for(vector<Vehicle *>::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
59                 delete *i;
60         layout.remove_train(*this);
61 }
62
63 void Train::set_name(const string &n)
64 {
65         name = n;
66
67         signal_name_changed.emit(name);
68 }
69
70 Vehicle &Train::get_vehicle(unsigned i)
71 {
72         if(i>=vehicles.size())
73                 throw InvalidParameterValue("Vehicle index out of range");
74         return *vehicles[i];
75 }
76
77 const Vehicle &Train::get_vehicle(unsigned i) const
78 {
79         if(i>=vehicles.size())
80                 throw InvalidParameterValue("Vehicle index out of range");
81         return *vehicles[i];
82 }
83
84 void Train::set_speed(unsigned speed)
85 {
86         if(speed==target_speed)
87                 return;
88         travel_speed = static_cast<int>(round(get_real_speed(speed)*87*3.6/5))*5;
89
90         target_speed = speed;
91         if(!target_speed)
92         {
93                 pending_block = 0;
94                 stop_timeout = Time::now()+(800+current_speed*150)*Time::msec;
95         }
96         else
97                 reserve_more();
98
99         signal_target_speed_changed.emit(target_speed);
100
101         update_speed();
102         pure_speed = false;
103 }
104
105 void Train::set_reverse(bool rev)
106 {
107         if(rev==reverse)
108                 return;
109
110         if(target_speed)
111         {
112                 set_speed(0);
113                 return;
114         }
115         else if(stop_timeout)
116                 return;
117
118         layout.get_driver().set_loco_reverse(address, rev);
119
120         release_blocks(rsv_blocks);
121         reverse_blocks(cur_blocks);
122 }
123
124 void Train::set_function(unsigned func, bool state)
125 {
126         if(!loco_type.get_functions().count(func))
127                 throw InvalidParameterValue("Invalid function");
128         if(func<5)
129                 layout.get_driver().set_loco_function(address, func, state);
130         else
131                 layout.get_driver().set_loco_function(address+1, func-4, state);
132 }
133
134 bool Train::get_function(unsigned func) const
135 {
136         return (functions>>func)&1;
137 }
138
139 void Train::set_route(const Route *r)
140 {
141         if(!rsv_blocks.empty())
142         {
143                 for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
144                         if(i->block->get_sensor_id())
145                         {
146                                 release_blocks(rsv_blocks, ++i, rsv_blocks.end());
147                                 break;
148                         }
149         }
150
151         route = r;
152         next_route = 0;
153         end_of_route = false;
154
155         if(route)
156         {
157                 BlockRef &last = (rsv_blocks.empty() ? cur_blocks.back() : rsv_blocks.back());
158                 BlockRef next = last.next();
159                 const Block::Endpoint &ep = next.block->get_endpoints()[next.entry];
160                 if(!route->get_tracks().count(ep.track))
161                 {
162                         next_route = route;
163                         route = Route::find(*ep.track, ep.track_ep, *next_route);
164                 }
165         }
166
167         if(target_speed && reserve_more()<2)
168                 update_speed();
169
170         signal_route_changed.emit(route);
171 }
172
173 void Train::go_to(const Track &to)
174 {
175         for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
176                 if(i->block->get_tracks().count(const_cast<Track *>(&to)))
177                 {
178                         set_speed(0);
179                         set_route(0);
180                         return;
181                 }
182
183         BlockRef *last = 0;
184         if(rsv_blocks.empty())
185                 last = &cur_blocks.back();
186         else
187         {
188                 for(list<BlockRef>::iterator i=rsv_blocks.begin(); (i!=rsv_blocks.end() && !last); ++i)
189                         if(i->block->get_sensor_id())
190                                 last = &*i;
191         }
192
193         BlockRef next = last->next();
194         const Block::Endpoint &ep = next.block->get_endpoints()[next.entry];
195
196         set_route(Route::find(*ep.track, ep.track_ep, to));
197 }
198
199 void Train::place(Block &block, unsigned entry)
200 {
201         if(target_speed)
202                 set_speed(0);
203
204         release_blocks(rsv_blocks);
205         release_blocks(cur_blocks);
206
207         if(!block.reserve(this))
208         {
209                 set_status("Unplaced");
210                 return;
211         }
212
213         cur_blocks.push_back(BlockRef(&block, entry));
214         if(reverse)
215         {
216                 unsigned exit = block.traverse(entry);
217                 const Block::Endpoint &bep = block.get_endpoints()[exit];
218                 Track *track = bep.track->get_link(bep.track_ep);
219                 unsigned ep = track->get_endpoint_by_link(*bep.track);
220                 vehicles.front()->place(track, ep, 0, Vehicle::FRONT_BUFFER);
221         }
222         else
223         {
224                 const Block::Endpoint &bep = block.get_endpoints()[entry];
225                 vehicles.front()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
226         }
227
228         set_status("Stopped");
229 }
230
231 bool Train::free_block(Block &block)
232 {
233         unsigned nsens = 0;
234         for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
235         {
236                 if(i->block==&block)
237                 {
238                         if(nsens<1)
239                                 return false;
240                         release_blocks(rsv_blocks, i, rsv_blocks.end());
241                         update_speed();
242                         return true;
243                 }
244                 else if(i->block->get_sensor_id())
245                         ++nsens;
246         }
247
248         return false;
249 }
250
251 int Train::get_entry_to_block(Block &block) const
252 {
253         for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
254                 if(i->block==&block)
255                         return i->entry;
256         for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
257                 if(i->block==&block)
258                         return i->entry;
259         return -1;
260 }
261
262 void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
263 {
264         if(stop_timeout && t>=stop_timeout)
265         {
266                 release_blocks(rsv_blocks);
267                 end_of_route = false;
268                 stop_timeout = Time::TimeStamp();
269         }
270
271         if(current_speed)
272         {
273                 Track *track = vehicles[0]->get_track();
274
275                 bool ok = false;
276                 for(list<BlockRef>::const_iterator i=cur_blocks.begin(); (!ok && i!=cur_blocks.end()); ++i)
277                         ok = i->block->get_tracks().count(track);
278
279                 if(ok)
280                 {
281                         float d = get_real_speed(current_speed)*(dt/Time::sec);
282                         vehicles[0]->advance(reverse ? -d : d);
283                 }
284         }
285 }
286
287 void Train::save(list<DataFile::Statement> &st) const
288 {
289         st.push_back((DataFile::Statement("name"), name));
290         for(unsigned i=0; i<=14; ++i)
291                 if(real_speed[i].weight)
292                         st.push_back((DataFile::Statement("real_speed"), i, real_speed[i].speed, real_speed[i].weight));
293
294         if(!cur_blocks.empty())
295         {
296                 list<BlockRef> blocks = cur_blocks;
297                 if(reverse)
298                         reverse_blocks(blocks);
299
300                 Block *prev = blocks.front().block->get_endpoints()[blocks.front().entry].link;
301                 st.push_back((DataFile::Statement("block_hint"), prev->get_id()));
302
303                 for(list<BlockRef>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
304                         st.push_back((DataFile::Statement("block"), i->block->get_id()));
305         }
306
307         if(route)
308                 st.push_back((DataFile::Statement("route"), route->get_name()));
309 }
310
311 void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev)
312 {
313         if(addr==address)
314         {
315                 current_speed = speed;
316                 reverse = rev;
317
318                 signal_speed_changed.emit(current_speed);
319                 signal_reverse_changed.emit(reverse);
320         }
321 }
322
323 void Train::loco_func_event(unsigned addr, unsigned func, bool state)
324 {
325         if(addr==address || (addr==address+1 && loco_type.get_max_function()>4))
326         {
327                 if(addr==address+1)
328                         func += 4;
329                 if(state)
330                         functions |= 1<<func;
331                 else
332                         functions &= ~(1<<func);
333
334                 signal_function_changed.emit(func, state);
335         }
336 }
337
338 void Train::sensor_event(unsigned addr, bool state)
339 {
340         if(state)
341         {
342                 // Find the first sensor block from our reserved blocks that isn't this sensor
343                 list<BlockRef>::iterator i;
344                 for(i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
345                         if(i->block->get_sensor_id() && i->block->get_sensor_id()!=addr)
346                                 break;
347
348                 if(i!=rsv_blocks.begin())
349                 {
350                         // Compute speed and update related state
351                         float travel_time_secs = (Time::now()-last_entry_time)/Time::sec;
352                         travel_speed = static_cast<int>(round(travel_dist/travel_time_secs*87*3.6/5))*5;
353
354                         if(pure_speed)
355                         {
356                                 RealSpeed &rs = real_speed[current_speed];
357                                 rs.add(travel_dist/travel_time_secs, travel_time_secs);
358                         }
359
360                         travel_dist = 0;
361                         float block_len;
362                         for(list<BlockRef>::iterator j=rsv_blocks.begin(); j!=i; ++j)
363                         {
364                                 j->block->traverse(j->entry, &block_len);
365                                 travel_dist += block_len;
366
367                                 if(j->block->get_sensor_id()==addr)
368                                 {
369                                         const Block::Endpoint &bep = j->block->get_endpoints()[j->entry];
370                                         if(reverse)
371                                         {
372                                                 Track *track = bep.track->get_link(bep.track_ep);
373                                                 unsigned ep = track->get_endpoint_by_link(*bep.track);
374                                                 vehicles.back()->place(track, ep, 0, Vehicle::BACK_AXLE);
375                                         }
376                                         else
377                                                 vehicles.front()->place(bep.track, bep.track_ep, 0, Vehicle::FRONT_AXLE);
378                                 }
379                         }
380                         last_entry_time = Time::now();
381                         pure_speed = true;
382
383                         // Check if we've reached the next route
384                         if(next_route)
385                         {
386                                 const set<const Track *> &rtracks = next_route->get_tracks();
387                                 for(list<BlockRef>::iterator j=rsv_blocks.begin(); j!=i; ++j)
388                                         if(rtracks.count(j->block->get_endpoints()[j->entry].track))
389                                         {
390                                                 route = next_route;
391                                                 next_route = 0;
392                                                 // XXX Exceptions?
393                                                 signal_route_changed.emit(route);
394                                                 break;
395                                         }
396                         }
397
398                         // Move blocks up to the next sensor to our current blocks
399                         cur_blocks.splice(cur_blocks.end(), rsv_blocks, rsv_blocks.begin(), i);
400
401                         // Try to get more blocks if we're moving
402                         if(target_speed)
403                         {
404                                 unsigned nsens = reserve_more();
405                                 if(!nsens && end_of_route)
406                                 {
407                                         set_speed(0);
408                                         set_route(0);
409                                 }
410                                 else if(nsens<2)
411                                         update_speed();
412                         }
413                 }
414         }
415         else
416         {
417                 // Find the first sensor in our current blocks that's still active
418                 list<BlockRef>::iterator end = cur_blocks.begin();
419                 for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
420                         if(i->block->get_sensor_id())
421                         {
422                                 if(layout.get_driver().get_sensor(i->block->get_sensor_id()))
423                                         break;
424                                 else
425                                         end = i;
426                         }
427                 
428                 if(end!=cur_blocks.begin())
429                 {
430                         // Free blocks up to the last inactive sensor
431                         ++end;
432                         release_blocks(cur_blocks, cur_blocks.begin(), end);
433                 }
434         }
435 }
436
437 void Train::turnout_event(unsigned addr, bool)
438 {
439         if(pending_block)
440         {
441                 unsigned pending_addr = pending_block->get_turnout_id();
442                 bool double_addr = (*pending_block->get_tracks().begin())->get_type().is_double_address();
443                 if(addr==pending_addr || (double_addr && addr==pending_addr+1))
444                         reserve_more();
445         }
446 }
447
448 void Train::block_reserved(const Block &block, const Train *train)
449 {
450         if(&block==pending_block && !train)
451                 reserve_more();
452 }
453
454 unsigned Train::reserve_more()
455 {
456         BlockRef *last = 0;
457         if(!rsv_blocks.empty())
458                 last = &rsv_blocks.back();
459         else if(!cur_blocks.empty())
460                 last = &cur_blocks.back();
461         if(!last)
462                 return 0;
463
464         pending_block = 0;
465
466         // See how many sensor blocks we already have
467         unsigned nsens = 0;
468         for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
469                 if(i->block->get_sensor_id())
470                         ++nsens;
471         
472         const Route *cur_route = 0;
473         if(route)
474         {
475                 unsigned exit = last->block->traverse(last->entry);
476                 Track *track = last->block->get_endpoints()[exit].track;
477                 if(route->get_tracks().count(track))
478                         cur_route = route;
479                 else if(next_route && next_route->get_tracks().count(track))
480                         cur_route = next_route;
481         }
482
483         bool got_more = false;
484         BlockRef *good = last;
485         unsigned good_sens = nsens;
486         while(good_sens<3)
487         {
488                 // Traverse to the next block
489                 unsigned exit = last->block->traverse(last->entry);
490                 Block *link = last->block->get_link(exit);
491                 if(!link)
492                         break;
493
494                 int entry = link->get_endpoint_by_link(*last->block);
495                 if(entry<0)
496                         throw LogicError("Block links are inconsistent!");
497
498                 const Block::Endpoint &entry_ep = link->get_endpoints()[entry];
499
500                 if(cur_route)
501                 {
502                         if(cur_route!=next_route && next_route && next_route->get_tracks().count(entry_ep.track))
503                                 cur_route = next_route;
504                         else if(!cur_route->get_tracks().count(entry_ep.track))
505                         {
506                                 // Keep the blocks if we arrived at the end of the route
507                                 good = last;
508                                 good_sens = nsens;
509                                 end_of_route = true;
510                                 break;
511                         }
512                 }
513                 else if(route && route->get_tracks().count(entry_ep.track))
514                         cur_route = route;
515
516                 if(!link->reserve(this))
517                 {
518                         // If we found another train and it's not headed straight for us, we can keep the blocks we got
519                         int other_entry = link->get_train()->get_entry_to_block(*link);
520                         if(other_entry<0)
521                                 throw LogicError("Block reservation inconsistency");
522                         if(static_cast<unsigned>(entry)!=link->traverse(other_entry))
523                         {
524                                 good = last;
525                                 good_sens = nsens;
526                         }
527                         pending_block = link;
528                         break;
529                 }
530
531                 if(link->get_turnout_id())
532                 {
533                         const Endpoint &track_ep = entry_ep.track->get_type().get_endpoints()[entry_ep.track_ep];
534
535                         // Keep the blocks reserved so far, as either us or the other train can diverge
536                         good = last;
537                         good_sens = nsens;
538
539                         // Figure out what path we'd like to take on the turnout
540                         int path = -1;
541                         if(cur_route)
542                                 path = cur_route->get_turnout(link->get_turnout_id());
543                         if(path<0)
544                                 path = entry_ep.track->get_active_path();
545                         if(!((track_ep.paths>>path)&1))
546                         {
547                                 for(unsigned i=0; track_ep.paths>>i; ++i)
548                                         if((track_ep.paths>>i)&1)
549                                                 path = i;
550                         }
551
552                         if(path!=static_cast<int>(entry_ep.track->get_active_path()))
553                         {
554                                 // The turnout is set to wrong path - switch and wait for it
555                                 link->reserve(0);
556                                 pending_block = link;
557                                 entry_ep.track->set_active_path(path);
558                                 break;
559                         }
560                 }
561
562                 rsv_blocks.push_back(BlockRef(link, entry));
563                 last = &rsv_blocks.back();
564                 if(last->block->get_sensor_id())
565                 {
566                         ++nsens;
567                         got_more = true;
568                 }
569         }
570
571         // Unreserve blocks that were not good
572         while(!rsv_blocks.empty() && last!=good)
573         {
574                 last->block->reserve(0);
575                 rsv_blocks.erase(--rsv_blocks.end());
576                 if(!rsv_blocks.empty())
577                         last = &rsv_blocks.back();
578         }
579
580         if(got_more)
581                 update_speed();
582
583         return good_sens;
584 }
585
586 void Train::update_speed()
587 {
588         Driver &driver = layout.get_driver();
589
590         unsigned speed;
591         if(!target_speed)
592         {
593                 speed = 0;
594                 set_status("Stopped");
595         }
596         else
597         {
598                 unsigned nsens = 0;
599                 for(list<BlockRef>::const_iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
600                         if(i->block->get_sensor_id())
601                                 ++nsens;
602
603                 unsigned slow_speed = find_speed(0.1);  // 31.3 km/h
604                 if(nsens==0)
605                 {
606                         speed = 0;
607                         pure_speed = false;
608                         set_status("Blocked");
609                 }
610                 else if(nsens==1 && target_speed>slow_speed)
611                 {
612                         speed = slow_speed;
613                         pure_speed = false;
614                         set_status("Slow");
615                 }
616                 else
617                 {
618                         speed = target_speed;
619                         set_status(format("Traveling %d kmh", travel_speed));
620                 }
621         }
622
623         driver.set_loco_speed(address, speed);
624 }
625
626 float Train::get_real_speed(unsigned i) const
627 {
628         if(real_speed[i].weight)
629                 return real_speed[i].speed;
630
631         unsigned low;
632         unsigned high;
633         for(low=i; low>0; --low)
634                 if(real_speed[low].weight)
635                         break;
636         for(high=i; high<14; ++high)
637                 if(real_speed[high].weight)
638                         break;
639
640         if(real_speed[high].weight)
641         {
642                 if(real_speed[low].weight)
643                 {
644                         float f = float(i-low)/(high-low);
645                         return real_speed[low].speed*(1-f)+real_speed[high].speed*f;
646                 }
647                 else
648                         return real_speed[high].speed*float(i)/high;
649         }
650         else if(real_speed[low].weight)
651                 return real_speed[low].speed*float(i)/low;
652         else
653                 return 0;
654 }
655
656 unsigned Train::find_speed(float real) const
657 {
658         if(real<=real_speed[0].speed)
659                 return 0;
660
661         unsigned low = 0;
662         unsigned high = 0;
663         for(unsigned i=0; (!high && i<=14); ++i)
664                 if(real_speed[i].weight)
665                 {
666                         if(real_speed[i].speed<real)
667                                 low = i;
668                         else
669                                 high = i;
670                 }
671         if(!high)
672         {
673                 if(!low)
674                         return 0;
675                 return min(static_cast<unsigned>(low*real/real_speed[low].speed), 14U);
676         }
677
678         float f = (real-real_speed[low].speed)/(real_speed[high].speed-real_speed[low].speed);
679         return static_cast<unsigned>(low*(1-f)+high*f+0.5);
680 }
681
682 void Train::set_status(const string &s)
683 {
684         status = s;
685         signal_status_changed.emit(s);
686 }
687
688 void Train::release_blocks(list<BlockRef> &blocks)
689 {
690         release_blocks(blocks, blocks.begin(), blocks.end());
691 }
692
693 void Train::release_blocks(list<BlockRef> &blocks, list<BlockRef>::iterator begin, list<BlockRef>::iterator end)
694 {
695         while(begin!=end)
696         {
697                 Block *block = begin->block;
698                 blocks.erase(begin++);
699                 block->reserve(0);
700         }
701 }
702
703 void Train::reverse_blocks(list<BlockRef> &blocks) const
704 {
705         blocks.reverse();
706         for(list<BlockRef>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
707                 i->entry = i->block->traverse(i->entry);
708 }
709
710
711 Train::BlockRef::BlockRef(Block *b, unsigned e):
712         block(b),
713         entry(e)
714 { }
715
716 Train::BlockRef Train::BlockRef::next() const
717 {
718         Block *blk = block->get_endpoints()[block->traverse(entry)].link;
719         if(!blk)
720                 throw InvalidState("At end of line");
721
722         int ep = blk->get_endpoint_by_link(*block);
723         if(ep<0)
724                 throw LogicError("Block links are inconsistent");
725
726         return BlockRef(blk, ep);
727 }
728
729
730 Train::RealSpeed::RealSpeed():
731         speed(0),
732         weight(0)
733 { }
734
735 void Train::RealSpeed::add(float s, float w)
736 {
737         speed = (speed*weight+s*w)/(weight+w);
738         weight = min(weight+w, 300.0f);
739 }
740
741
742 Train::Loader::Loader(Train &t):
743         DataFile::BasicLoader<Train>(t),
744         prev_block(0)
745 {
746         add("block",       &Loader::block);
747         add("block_hint",  &Loader::block_hint);
748         add("name",        &Loader::name);
749         add("real_speed",  &Loader::real_speed);
750         add("route",       &Loader::route);
751 }
752
753 void Train::Loader::block(unsigned id)
754 {
755         Block &blk = obj.layout.get_block(id);
756         int entry = -1;
757         if(prev_block)
758                 entry = blk.get_endpoint_by_link(*prev_block);
759         if(entry<0)
760                 entry = 0;
761
762         blk.reserve(&obj);
763         obj.cur_blocks.push_back(BlockRef(&blk, entry));
764         obj.set_status("Stopped");
765         const Block::Endpoint &bep = blk.get_endpoints()[entry];
766         obj.vehicles.back()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
767
768         if(blk.get_sensor_id())
769                 obj.layout.get_driver().set_sensor(blk.get_sensor_id(), true);
770
771         prev_block = &blk;
772 }
773
774 void Train::Loader::block_hint(unsigned id)
775 {
776         prev_block = &obj.layout.get_block(id);
777 }
778
779 void Train::Loader::name(const string &n)
780 {
781         obj.set_name(n);
782 }
783
784 void Train::Loader::real_speed(unsigned i, float speed, float weight)
785 {
786         obj.real_speed[i].speed = speed;
787         obj.real_speed[i].weight = weight;
788 }
789
790 void Train::Loader::route(const string &n)
791 {
792         obj.set_route(&obj.layout.get_route(n));
793 }
794
795 } // namespace Marklin