]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.cpp
Add some shortcut functions for getting endpoints
[r2c2.git] / source / libmarklin / train.cpp
index e4afef7e37c516b17e74960e73e88d39f7bb8fd7..d9bade7dca338c5f20a53ca2624f53f2d4420298 100644 (file)
@@ -291,7 +291,7 @@ bool Train::divert(Track &from)
                        int route_path = route->route->get_turnout(from.get_turnout_id());
 
                        // Check that more than one path is available
-                       unsigned ep_paths = track->get_type().get_endpoints()[track.entry()].paths;
+                       unsigned ep_paths = track.endpoint().paths;
                        if(!(ep_paths&(ep_paths-1)))
                                return false;
 
@@ -391,7 +391,7 @@ void Train::place(Block &block, unsigned entry)
        }
        else
        {
-               const Block::Endpoint &bep = block.get_endpoints()[entry];
+               const Block::Endpoint &bep = block.get_endpoint(entry);
                vehicles.back()->place(*bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
        }
 }
@@ -730,9 +730,9 @@ void Train::sensor_event(unsigned addr, bool state)
                        // Check if we've reached the next route
                        if(routes.size()>1)
                        {
-                               const set<Track *> &rtracks = (++routes.begin())->route->get_tracks();
+                               const Route &route = *(++routes.begin())->route;
                                for(BlockList::iterator j=cur_blocks_end; j!=end; ++j)
-                                       if(rtracks.count((*j)->get_endpoints()[j->entry()].track))
+                                       if(route.has_track(*j->track_iter()))
                                        {
                                                routes.pop_front();
                                                // XXX Exceptions?
@@ -952,7 +952,7 @@ void Train::reserve_more()
 
                if(block->get_turnout_id())
                {
-                       const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+                       const TrackType::Endpoint &track_ep = track.endpoint();
                        bool multiple_paths = (track_ep.paths&(track_ep.paths-1));
 
                        if(multiple_paths && cur_route!=routes.end() && cur_route->diversion!=block->get_turnout_id())
@@ -1006,14 +1006,14 @@ void Train::check_turnout_paths(bool set)
                if((*i)->get_turnout_id())
                {
                        TrackIter track = i->track_iter();
-                       const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+                       const TrackType::Endpoint &track_ep = track.endpoint();
 
                        unsigned path = 0;
                        list<BlockIter>::iterator j = i;
                        if(++j!=blocks.end())
                        {
                                TrackIter rev = j->track_iter().flip();
-                               unsigned mask = rev->get_type().get_endpoints()[rev.entry()].paths&track_ep.paths;
+                               unsigned mask = rev.endpoint().paths&track_ep.paths;
                                for(path=0; mask>1; mask>>=1, ++path) ;
                        }
                        else