]> git.tdb.fi Git - r2c2.git/commitdiff
Use beam gates for positioning vehicles
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Jul 2013 18:39:34 +0000 (21:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Jul 2013 18:39:34 +0000 (21:39 +0300)
source/libr2c2/train.cpp

index b5f600e09e3a58a9744cbef5e7844cf57252aa78..02e9d31797e2faf6737288ba68c38829b98a0bdb 100644 (file)
@@ -6,6 +6,7 @@
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
 #include "aicontrol.h"
+#include "beamgate.h"
 #include "block.h"
 #include "catalogue.h"
 #include "driver.h"
@@ -475,6 +476,25 @@ void Train::sensor_state_changed(Sensor &sensor, Sensor::State state)
                                vehicles.front()->place(track, 0, Vehicle::FRONT_AXLE);
                }
        }
+       else if(BeamGate *gate = dynamic_cast<BeamGate *>(&sensor))
+       {
+               if(!advancing && vehicles.front()->get_track())
+               {
+                       TrackIter track = allocator.iter_for(*block).track_iter();
+                       for(; (track && &track->get_block()==block); track=track.next())
+                               if(track.track()==gate->get_track())
+                               {
+                                       if(reverse)
+                                               track = track.reverse();
+                                       float offset = gate->get_offset_from_endpoint(track.entry());
+                                       if(reverse)
+                                               vehicles.back()->place(track, offset, Vehicle::BACK_BUFFER);
+                                       else
+                                               vehicles.front()->place(track, offset, Vehicle::FRONT_BUFFER);
+                                       break;
+                               }
+               }
+       }
 }
 
 void Train::halt_event(bool h)