From 0c1214ad0680c3bf65c1ee5f366dbafabc9d188d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 10 Jul 2013 21:39:34 +0300 Subject: [PATCH] Use beam gates for positioning vehicles --- source/libr2c2/train.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index b5f600e..02e9d31 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -6,6 +6,7 @@ #include #include #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(&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) -- 2.45.2