]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.cpp
Correctly handle slope when snapping tracks
[r2c2.git] / source / libmarklin / train.cpp
index 341921aaf511000a406869cd78f0b566641ec420..09f587020588bc69fd91c5f51d2747a9094a7110 100644 (file)
@@ -36,6 +36,8 @@ Train::Train(TrafficManager &tm, Locomotive &l):
 {
        trfc_mgr.add_train(this);
 
+       loco.signal_reverse_changed.connect(sigc::mem_fun(this, &Train::locomotive_reverse_changed));
+
        const map<unsigned, Sensor *> &sensors = trfc_mgr.get_control().get_sensors();
        for(map<unsigned, Sensor *>::const_iterator i=sensors.begin(); i!=sensors.end(); ++i)
                i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::sensor_event), i->second));
@@ -75,6 +77,11 @@ void Train::set_speed(unsigned speed)
        pure_speed = false;
 }
 
+void Train::set_reverse(bool rev)
+{
+       loco.set_reverse(rev);
+}
+
 void Train::place(Block *block, unsigned entry)
 {
        for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end();)
@@ -166,6 +173,18 @@ void Train::save(list<DataFile::Statement> &st) const
        st.push_back((DataFile::Statement("speed_scale"), speed_scale, speed_scale_weight));
 }
 
+void Train::locomotive_reverse_changed(bool)
+{
+       for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+               i->block->reserve(0);
+       rsv_blocks.clear();
+       cur_blocks.reverse();
+       for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
+               i->entry = i->block->traverse(i->entry);
+       reserve_more();
+       update_speed();
+}
+
 void Train::sensor_event(bool state, Sensor *sensor)
 {
        unsigned addr = sensor->get_address();